I have no problem creating multiple view holders in a recyclerview. The problem I am having it determining the positioning the the headers and items.
I am creating a gallery app and I want to have my album names as headers and put 8 images for each album. So you would have a header with album title then 8 pictures from that album. then the next header with album title and 8 pictures from that album. And continue on with that scheme. If there is less than 8 pictures i want to leave those blank until the next header would start.
I have two ArrayList i am getting my data from. Albums and Media.
I am trying to set the type in getItemViewType of my adapter but can't figure out how to set them like mentioned above. Whats confusing me is trying to set position with multiple arraylist and unknown number of pictures for each album.
Again this is not another question like the many I have seen about setting up multiple view holders in a recyclerview. I have that concept. My problem is determining positioning for the view holders.
This is how my create and bind views look to give some context
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == ALBUM_TYPE) {
return new AlbumHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view, parent, false));
} else if (viewType == HEAD_TYPE) {
return new HeadHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.header_text, parent, false));
} else {
return new MediaHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.card_photo, parent, false));
}
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (holder instanceof AlbumHolder) {
Album m = albums.get(position);
((AlbumHolder)holder).bindView(m, position);
} else if (holder instanceof HeadHolder) {
if (sortingMode == SortingMode.FOLDER) {
Album m = albums.get(position);
((HeadHolder)holder).bindView(m.getName(), position);
} else {
String m = sortListYear.get(position);
((HeadHolder)holder).bindView(m, position);
}
} else {
Media m = media.get(position);
((MediaHolder)holder).bindView(m, position);
}
}
The ALBUM_TYPE is not used for this question I am asking. Just the HEAD_TYPE AND MEDIA_TYPE.