[英]How to reset recyclerView items befor going to another activity?
I have a recyclerView. One of
我有一个
recyclerView. One of
recyclerView. One of
recyclerView items has an onClick
method. recyclerView. One of
recyclerView项目具有onClick
方法。 In this method, I setVisibility
for one Item to Visible(default is gone).在这种方法中,我
setVisibility
一个项目可见(默认为走了)。
onClick :点击:
public void onClickImageView(ImageView imageView) {
imageView.setVisibility(View.VISIBLE);
}
Now My problem is : When i go to another activity and then come back to this activity, I want to the ImageView visibility be reset to default (gone) but it still visible.现在我的问题是:当我去另一个活动然后回到这个活动时,我想将 ImageView 可见性重置为默认值(消失)但它仍然可见。
Note : This may have happened in more than one row, I want all changed rows to be reset to default.注意:这可能发生在不止一行,我希望所有更改的行都重置为默认值。
Note : I have used data binding
注意:我使用过
data binding
Any Activity that restarts has its onResume()
method executed first.任何重新启动的 Activity 都会首先执行其
onResume()
方法。 So, call notifyDataSetChanged()
of RcyclerView
from onResume()
因此,从
onResume()
调用notifyDataSetChanged()
的RcyclerView
onResume()
@Override
public void onResume(){
super.onResume();
mAdapter.notifyDataSetChanged();
}
there's workaround you can try for this,有解决方法你可以试试这个,
create a function in your activity在您的活动中创建一个函数
function void updateRecyclerView(position){
yourArrayListForVisibility.set(position,'hide');
mAdapter.notifyDataSetChanged();
}
@Override
public void onResume(){
super.onResume();
mAdapter.notifyDataSetChanged();
}
call this function in your adapter before intent and in your adapter check for this arraylist value to hide or show content, always set default value to 'yourArrayListForVisibility' for every position在意图之前在您的适配器中调用此函数,并在您的适配器中检查此数组列表值以隐藏或显示内容,始终将每个位置的默认值设置为“yourArrayListForVisibility”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.