Search code examples
androidandroid-recyclerviewonactivityresultstartactivityforresult

Adapter with startActivityForResult


Good Day everybody i want edit item of Recycle-view startAcivityForResult/onActivityResult my code in BindHolder

        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);
        }
    });

in BindHolder the value is null but here it work correctly

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);
        }
    }
}

Any hint please ! Thanks so much for everybody


Solution

  • Find the position of your item pos in the adapter and call

      adapter.notifyItemChanged(pos)
    

    This will result in calling onBindViewHolder for that position.

    If it is absolutely impossible to know the position call

    adapter.notifyDataSetChanged()
    

    This will result in onBindViewHolder called for every visible item in the adapter