@Override
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
MyDB db = new MyDB(mContext);
ArrayList<String> images1=db.getCollection(1); // Returns 2 image URIs in an array
ArrayList<String> images2=db.getCollection(2); // 0 images
ArrayList<String> images3=db.getCollection(3); // 2 images
ArrayList<String> images4=db.getCollection(4); // 10 images
ArrayList<String> images5=db.getCollection(5); // 5 images
ArrayList<String> images6=db.getCollection(6); // 12 images
//Maximum 12 images per collection
I've tried:
for(int i=0;i<images1.size();i++){
String path1=images1.get(i);
holder.img1.setImageURI(Uri.parse(path1));
}
for(int j=0;j<images2.size();j++){
String path2=images2.get(i);
holder.img2.setImageURI(Uri.parse(path2));
}
for(int k=0;k<images3.size();k++){
String path3=images3.get(i);
holder.img3.setImageURI(Uri.parse(path3));
}
//Sets each view the same, of course.
How do I get recyclerview to assign each view to a different collection of 12 images(or less)?
Since the collection can grow in size, is there another way to get unique images(upto 12) into each view of RecyclerView?
A position element is returned in bindViewHolder where you can use that..1st you have to take 12 ImageViews and assign them in a array of imageViews. let it take imgs[]
@Override
public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
MyDB db = new MyDB(mContext);
ArrayList<String> images1=db.getCollection(position);
for(int i=0;i<images1.size();i++){
String path1=images1.get(i);
holder.imgs[i].setImageURI(Uri.parse(path1));
}
@override
int getItemCount(){
return 6;
}