Create a RecyclerView with multiple view from layouts

前端 未结 3 873
傲寒
傲寒 2020-12-06 16:14

I am trying to have 2 layout in one RecyclerView

I have a recycler view list which is called Bookmark and it is parsed from an xml and this is all working , but I wa

3条回答
  •  温柔的废话
    2020-12-06 16:35

    You can use different layouts on the same RecyclerView , just override adapter getItemViewType() method and return a different int value for the button layout, in your example you should return for example 1 for the normal item and 2 for the button item.

    The view type is passed as argument to onCreateViewHolder() method and depending of the viewType value you inflate the normal layout or the button layout.

    It seems that you need also make getItemCount() to return one more than the array size

    Hope it will help

    Here an example: How to create RecyclerView with multiple view type?

提交回复
热议问题