[英]How to handle Horizontal RecyclerView inside Vertical RecyclerView
I am using a RecyclerView and inside this I added a Horizontal RecyclerView for showing images like a gallery. 我正在使用RecyclerView,并且在其中添加了Horizontal RecyclerView,用于显示像画廊这样的图像。
I am inserting my RecyclerView rows one by one after user enter his details. 在用户输入详细信息后,我将一一插入RecyclerView行。
My main problem is I am selecting images through Camera or Gallery, and they are displaying well in horizontal RecyclerView. 我的主要问题是我要通过“相机”或“图库”选择图像,它们在水平RecyclerView中的显示效果很好。
However, when a user adds one more cell, then some previous images are coming in that cell. 但是,当用户添加一个以上的单元格时,该单元格中就会出现一些以前的图像。 This is incorrect.
这是不正确的。
How can I resolve this problem? 我该如何解决这个问题?
private void addDoctorDetails() {
try {
personalInformatioDoctorCatogoryBeanArrayList.add(new PersonalInformatioDoctorCatogoryBean("Physician" + i, "MBBS" + i, "1985" + i,imagesBeanArrayList));
personalInformationRecyclerDoctorCatogoryAdapter.notifyDataSetChanged();
i++;
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
private List<PersonalInformatioDoctorCatogoryBean> personalInformatioDoctorCatogoryBeanList;
private Context context;
public PersonalInformationRecyclerDoctorCatogoryAdapter(Context context, List<PersonalInformatioDoctorCatogoryBean> personalInformatioDoctorCatogoryBeanList) {
this.context = context;
this.personalInformatioDoctorCatogoryBeanList = personalInformatioDoctorCatogoryBeanList;
}
@Override
public VHItem onCreateViewHolder(ViewGroup parent, int viewType) {
try {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_personal_information_step2_list_items, parent, false);
return new VHItem(v);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return null;
}
@Override
public void onBindViewHolder(VHItem viewHolder, final int position) {
try {
viewHolder.speciality.setText(personalInformatioDoctorCatogoryBeanList.get(position).getSpeciality());
viewHolder.qualification.setText(personalInformatioDoctorCatogoryBeanList.get(position).getQualification() + "(" + personalInformatioDoctorCatogoryBeanList.get(position).getYear() + ")");
//Getting imagesBeanArrayList position images
ArrayList<ImagesBean> imagesBeanArrayList = personalInformatioDoctorCatogoryBeanList.get(position).getImagesBeanList();
//Set Horizental recyclerView adapter
HorizontalListAdapter horizontalListAdapter = new HorizontalListAdapter(context, imagesBeanArrayList);
viewHolder.horizentalView.setHasFixedSize(true);
viewHolder.horizentalView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
viewHolder.horizentalView.setAdapter(horizontalListAdapter);
viewHolder.horizentalView.setNestedScrollingEnabled(false);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
@Override
public int getItemCount() {
return personalInformatioDoctorCatogoryBeanList.size();
}
class VHItem extends RecyclerView.ViewHolder {
private TextView speciality, qualification;
private RecyclerView horizentalView;
public VHItem(View view) {
super(view);
speciality = (TextView) view.findViewById(R.id.speciality_textview);
qualification = (TextView) view.findViewById(R.id.qualification_textview);
horizentalView = (RecyclerView) view.findViewById(R.id.horizontal_recycler);
}
}
private String speciality;
private String qualification;
private String year;
private ArrayList<ImagesBean> imagesBeanList;
public PersonalInformatioDoctorCatogoryBean(String speciality, String qualification, String year,ArrayList<ImagesBean> imagesBeanList) {
this.speciality = speciality;
this.qualification = qualification;
this.year = year;
this.imagesBeanList = imagesBeanList;
}
public String getSpeciality() {
return speciality;
}
public void setSpeciality(String speciality) {
this.speciality = speciality;
}
public String getQualification() {
return qualification;
}
public void setQualification(String qualification) {
this.qualification = qualification;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public ArrayList<ImagesBean> getImagesBeanList() {
return imagesBeanList;
}
public void setImagesBeanList(ArrayList<ImagesBean> imagesBeanList) {
this.imagesBeanList = imagesBeanList;
}
In my observation, you are passing same reference of imagesBeanArrayList
in each record insert. 根据我的观察,您在每个记录插入中传递了
imagesBeanArrayList
相同引用。 Try to pass fresh array when you add new one. 当您添加新数组时,尝试传递新数组。
private void addDoctorDetails() {
try {
personalInformatioDoctorCatogoryBeanArrayList.add(
new PersonalInformatioDoctorCatogoryBean(
"Physician" + i, "MBBS" + i, "1985" + i,
new ArrayList<ImagesBean>()));
personalInformationRecyclerDoctorCatogoryAdapter.notifyDataSetChanged();
i++;
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.