第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在RecyclerView.Adapter中使用onActivityResult

如何在RecyclerView.Adapter中使用onActivityResult

三國(guó)紛爭(zhēng) 2023-10-19 21:15:23
我想在 RecyclerView.Adapter 中使用onActivityResult。但我不明白這個(gè)釋放在我的情況下是如何進(jìn)行的。我有一個(gè)動(dòng)態(tài) RecyclerView.Adapterpublic class SettingsActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.layout_settings);        ArrayList<SettingsTypeModel> list= new ArrayList<>();        list.add(new SettingsTypeModel(SettingsTypeModel.TYPE_SEND_TO_MAIL));        list.add(new SettingsTypeModel(SettingsTypeModel.TYPE_SEND_TO_DRIVE));        SettingsRecyclerAdapter adapter = new SettingsRecyclerAdapter(list,this);        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, OrientationHelper.VERTICAL, false);        RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.recyclerVieww);        mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));        mRecyclerView.setLayoutManager(linearLayoutManager);        mRecyclerView.setItemAnimator(new DefaultItemAnimator());        mRecyclerView.setClickable(true);        mRecyclerView.setAdapter(adapter);    }    public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {        super.onActivityResult(requestCode, resultCode, data);    }    @Override    protected void onDestroy() {        super.onDestroy();    }    @Override    public void onBackPressed() {        super.onBackPressed();    }}單擊switchSendMailReport或 switchDriveReport 后,我需要調(diào)用函數(shù)onActivityResult。如何在RecyclerView.Adapter中使用onActivityResult?
查看完整描述

2 回答

?
慕運(yùn)維8079593

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超5個(gè)贊

在interface您的SettingsRecyclerAdapter:


  public interface OnAdapterResult {

            public void onAdapterResult(boolean isChecked);

        }

并將接口附加到其構(gòu)造函數(shù)中:


 public SettingsRecyclerAdapter (Context context){

            mContext = context;

            // .. Attach the interface

            try{

                onAdapterResult = (OnAdapterResult) context;

            }catch(ClassCastException ex){


                Log.e("MyAdapter","error"+ ex,);

            }

        }

然后初始化你的接口方法:


((SendToMailTypeViewHolder) holder).switchSendMailReport.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        @Override

                        public void onCheckedChanged(CompoundButton buttonView, 

                         boolean isChecked) {

                            if (isChecked) {

                            onAdapterResult.onAdapterResult(isChecked); \\ here

                            } else {


                            }

                        }

                    });

那么implements您的SettingsActivity來(lái)自adepter.OnAdapterResult interface:


public class SettingsActivity extends AppCompatActivity implements adepter.OnAdapterResult {

.

.

.



    @Override

        public void onAdapterResult(boolean isChecked) {

            // 

        }


}


查看完整回答
反對(duì) 回復(fù) 2023-10-19
?
慕仙森

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

您不能在適配器類中使用活動(dòng)的 onActivityResult() 。但您可以在適配器類中創(chuàng)建自己的相同方法

public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        // do you stuff
     }

現(xiàn)在,當(dāng)您在 onActivityResult() 中回調(diào)時(shí),從活動(dòng)中調(diào)用您的適配器方法

if(adapter !=null){
   adapter.onActivityResult(requestCode,resultCode,data)
}


查看完整回答
反對(duì) 回復(fù) 2023-10-19
  • 2 回答
  • 0 關(guān)注
  • 150 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)