简体   繁体   English

如何在进入另一个活动之前重置 recyclerView 项目?

[英]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.

相关问题 如何在 recyclerView 中设置 OnclickListener 以进行另一个活动 - How to set OnclickListener in recyclerView for going another activity 如何在按钮单击时从recyclerview检查项目以显示在另一个活动中recyclerview - how to checked items from recyclerview to show on another activity recyclerview on button click 如何在活动中访问 onBindViewHolder 的项目 RecyclerView - How to access onBindViewHolder's items RecyclerView in an activity 如何从活动片段中访问RecyclerView中的项目 - how to access items in RecyclerView in fragment from an activity 多个 RecyclerView 布局在转到另一个 RecyclerView 新活动时显示 IndexOutOfBoundsException - Multiple RecyclerView layout is showing IndexOutOfBoundsException when going to another RecyclerView new Activity 我如何知道 RecyclerView 将膨胀多少项? - How do I know how many items the RecyclerView is going to inflate? 使用多重选择回收视图将选定的项目传递到另一个活动 - Using Multi-select recyclerview to pass selected items to another activity 将项目从另一个活动添加到回收站视图的最佳方法? - Best method for adding items to a recyclerview from another activity? 如何更新来自其他活动的Recyclerview数据 - How to update Recyclerview data from another activity 如何将参考从RecyclerView传递到另一个活动 - How to pass reference from RecyclerView to another activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM