为了账号安全,请及时绑定邮箱和手机立即绑定

似乎没有收到“onActivityResult()”的结果

似乎没有收到“onActivityResult()”的结果

C#
一只名叫tom的猫 2022-11-22 15:13:06
我有两个活动,一个只有一个巨大的列表视图,另一个有一个纯文本和按钮。这个“newRoll”活动需要返回一个添加到 ObservableCollection 的字符串,我还没有实现 listView 更新的部分但是使用 logcat,我可以看出没有任何东西被添加到包含所有项目的 ObservableCollection。从我得到的信息来看,我对意图的工作方式有什么误解吗?主要活动:    //upon clicking any item in the listView this runs:    Intent NewRoll = new Intent(this, typeof(NewRoll));    StartActivityForResult(NewRoll, requestCode);protected void onActivityResult(int requestCode, int resultCode, Intent data)        {            //just holds the string                    holder = data.GetStringExtra("roll_name");            //adds it to an observable collection                    rolls.Add(holder);            //me trying to get something back                    Log.Info(rolls.Count.ToString(), "Roll Added");                    Log.Info(holder, "Please?");        }新卷://on button click//get whatever is in the plaintext                newRoll = rollName.Text;                data.PutExtra("roll_name",newRoll);                SetResult(Result.Ok, data);                Finish();
查看完整描述

2 回答

?
翻翻过去那场雪

TA贡献2065条经验 获得超13个赞

Xamarin的文档指出 Android.App.Activity.OnActivityResult 的签名是


[Android.Runtime.Register("onActivityResult", "(IILandroid/content/Intent;)V", "GetOnActivityResult_IILandroid_content_Intent_Handler")]

protected virtual Void OnActivityResult (Int32 requestCode, [Android.Runtime.GeneratedEnum] Result resultCode, Intent data)

所以你必须重写它来接收活动结果,比如


protected override Void OnActivityResult (Int32 requestCode, Result resultCode, Intent data)

{

    base.OnActivityResult(requestCode, resultCode, data);


    // do your stuff

}


查看完整回答
反对 回复 2022-11-22
?
斯蒂芬大帝

TA贡献1827条经验 获得超8个赞

protected void onActivityResult(int requestCode, int resultCode, Intent data)

    {

        //just holds the string

                holder = data.GetStringExtra("roll_name");

        //adds it to an observable collection

                rolls.Add(holder);

        //me trying to get something back

                Log.Info(rolls.Count.ToString(), "Roll Added");

                Log.Info(holder, "Please?");

    }

我在这里没有看到@Override注释。您确定要覆盖Activity基类方法onActivityResult吗?


查看完整回答
反对 回复 2022-11-22
  • 2 回答
  • 0 关注
  • 107 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信