我将ArrayList从Activity传递到RecyclerView适配器。但是活动中的更改值也会在适配器中更改值。我如何避免这种情况?
List<Object> objectList = Collections.synchronizedList(new ArrayList<Object>());
public RecyclerViewAdapter(Context context,List<Object> commentDatas) {
mContext = context;
commentDataList = commentDatas;
}
因为您没有显示代码,所以我将通过示例显示代码
创建适配器时,您可以通过适配器的构造器将数据发送到适配器,如下所示:
List<MyObject> list;
public RcvAdapter(List<MyObject> list, Context context) {
this.list = list;
this.context = context;
}
如果您想解决您的问题,请执行以下操作:
List<MyObject> list = new ArrayList<>();
public RcvAdapter(List<MyObject> list, Context context) {
this.list.addAll(list);
this.context = context;
}
希望对您有所帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句