rakesh kashyap
rakesh kashyap

Reputation: 1466

Showing different Footer layouts in RecyclerView

I would like to know what is the right way to implement a footer in RecyclerView which can be used to display different views. Few examples are as below

I came across https://stackoverflow.com/a/29168617/371557 which mentions that I have to Override getItemViewType and inflate different views in onCreateViewHolder

What I do not understand is how will RecyclerView know which ViewType it has to request for? How can I force the RecyclerView to show the ViewType?

Upvotes: 2

Views: 82

Answers (1)

J-Jamet
J-Jamet

Reputation: 857

RecyclerView is the new view more powerfull than listview, you can make a footer in this but it's for me not the right way. I recommend to create a layout include your RecyclerView and add a dedicated view like Snackbar or a custom footer.

For your question, the RecyclerView knows what to display with the getItemViewType(int positionItem) method.

For example, if the item in position 6 must be shown in the list, getItemViewType return the id of view in onCreateViewHolder(ViewGroup viewGroup, int id) method and recycle the view which could already be used in list for saving memory.

(Sorry for my poor English :)

Upvotes: 2

Related Questions