

- #ANDROID STUDIO RECYCLERVIEW MULTIPLE LAYOUTS HOW TO#
- #ANDROID STUDIO RECYCLERVIEW MULTIPLE LAYOUTS UPDATE#
#ANDROID STUDIO RECYCLERVIEW MULTIPLE LAYOUTS UPDATE#
* This method internally calls onBindViewHolder(ViewHolder, int) to update the layout_viewholder1.xml will be used for User objects and layout_viewholder2.xml will be used for String objects.įor the purpose of this exercise, we will modify our sample data set in RecyclerViewActivity to contain a list of objects as shown: private ArrayList getSampleArrayList () /** The following example will be inflating two different layouts for based on the object that the List holds. In particular, there are special methods to be overridden within the adapter:īuilding on top of the basic RecyclerView usage project, we will now replace the SimpleItemRecyclerViewAdapter with a more ComplexRecyclerViewAdapter which does all the heavy-lifting for inflating different types of layouts based on the item view type. To implement heterogeneous layouts inside the RecyclerView, most of the work is done within the RecyclerView.Adapter.
#ANDROID STUDIO RECYCLERVIEW MULTIPLE LAYOUTS HOW TO#
Note: Refer Implementing a Heterogeneous ListView guide on how to inflate multiple item types within a ListView.

This guide will explain how to inflate multiple view types inside your RecyclerView widget based on the item type. RecyclerView can also be used to inflate multiple view types in situations where your list might be heterogeneous, in the sense, based on the response from the server, there might be a requirement for inflating different types of layouts (example: Consider facebook home feed where there are a variety of stories such as a status update, location update, single image, image album, video, etc). We will be building on top of the classes from the above guide so it is very important that you have the basic RecyclerView up and running. Make sure you are familiar with RecyclerView by going through the following guide for basic usage of a RecyclerView.
