【问题标题】:Adapter with startActivityForResult带有 startActivityForResult 的适配器
【发布时间】:2016-05-18 19:29:57
【问题描述】:

大家好,我想在 BindHolder 中编辑 Recycle-view startAcivityForResult/onActivityResult 的项目

        holder.title.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent goToOrder= new Intent("Order");
            ((Activity)context).startActivityForResult(goToOrder , 10);
            mDataset.get(position).setType_meat(type_meat);
            mDataset.get(position).setType_rice(type_rice);
        }
    });

在 BindHolder 中值为 null 但在这里它可以正常工作

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case 10:
        if (resultCode == -1) {
            type_rice=data.getStringExtra("type_rice");
            type_meat=data.getStringExtra("type_meat");
            Log.e("type rice", type_rice);
            Log.e("type_meat", type_meat);
        }
    }
}

请给点提示! 非常感谢大家

【问题讨论】:

    标签: android android-recyclerview onactivityresult startactivityforresult


    【解决方案1】:

    在适配器中找到你的物品pos的位置并调用

      adapter.notifyItemChanged(pos)
    

    这将导致为该职位调用onBindViewHolder

    如果绝对不可能知道位置调用

    adapter.notifyDataSetChanged()
    

    这将导致为适配器中的每个可见项调用onBindViewHolder

    【讨论】:

    • 感谢重播,,,我试试你的想法,但它仍然是空值我打开新活动当我点击 itemTitle 对象的数据将改变取决于结果表单活动,
    猜你喜欢
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多