I am using the following code
in Adapter class to show data
in a RecyclerView, but now I would like to show data from some other ArrayList
in a same RecyclerView (at some positions
like: 1st position and 6th position) using different layout.
That different layout (assume: another_layout.xml) contains 2 TextViews and an Image, also want to implement click on listener for that layout too..
@Override
public PlaylistCardAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// inflate a card layout
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.youtube_video_card, parent, false);
// populate the viewholder
ViewHolder vh = new ViewHolder(v);
return vh;
}
RecyclerView for more than one layout
1. Override getItemViewType(int position) method
e.g I have two layouts layout1 and layout2.I want layout1 at the top and then layout2. So getItemViewType would be something like this
2. Different viewholder for each layout like this
3. Inflate different layouts according to the position
4. Bind your views as per the position
5.Now Most important getItemCount() method //return the number of views
Hope this helps!!!