亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

似乎沒有收到“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條經驗 獲得超14個贊

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 關注
  • 201 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號