回收视图适配器的不同实例具有相同的变量值



我有一个recyclerview适配器,它包含一个customclass列表并将它们显示在列表中,现在,在一个活动中,我需要这个适配器的多个实例,
,但当我尝试这个时,结果是扭曲的。当我向adapter_instance1添加一个新项目时,这是可以的,但当我想向adapteer_instance2添加一个项目时,我看到它的列表中还有另一个项目(来自adapter_stance1(这是我的适配器cpass定义

public class attachmentAdapter extends RecyclerView.Adapter<attachmentAdapter.attachmentViewHolder> {
private ArrayList<attachment> mUris;
....
....
....
}

这是初始化适配器:

attachmentAdapter first_adapter = new attachmentAdapter(new ArrayList<>(),"","",this,null)
attachmentAdapter second_one = new attachmentAdapter(new ArrayList<>(),"","",this,null)

你能告诉我我的代码出了什么问题吗?

您需要在适配器类中区分那些不同的视图持有者。

最新更新