带有 startActivityForResult 的适配器
Adapter with startActivityForResult
大家好,我想编辑回收视图的项目startAcivityForResult/onActivityResult我在 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);
}
});
在 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);
}
}
}
任何提示请!
非常感谢大家
找到你的项目 pos
在适配器中的位置并调用
adapter.notifyItemChanged(pos)
这将导致为该职位调用 onBindViewHolder
。
如果绝对不可能知道位置调用
adapter.notifyDataSetChanged()
这将导致 onBindViewHolder
为适配器中的每个可见项调用
大家好,我想编辑回收视图的项目startAcivityForResult/onActivityResult我在 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);
}
});
在 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);
}
}
}
任何提示请! 非常感谢大家
找到你的项目 pos
在适配器中的位置并调用
adapter.notifyItemChanged(pos)
这将导致为该职位调用 onBindViewHolder
。
如果绝对不可能知道位置调用
adapter.notifyDataSetChanged()
这将导致 onBindViewHolder
为适配器中的每个可见项调用