Android ListView with multiple layouts

前端 未结 3 597
清酒与你
清酒与你 2021-01-18 21:11

I have to show a list with different type of Views. So I have to define a ListView with an Adapter where I have to inflate multiple views. I have gone through example given,

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-18 21:55

    This is what you need to use when you different types of Views inside a ListView or RecyclerView :-

    getItemViewType() and getViewTypeCount()
    

    First you need to use getViewTypeCount() and return the number of unique views you need inside your List. Then override getItemViewType() and return the View type based on the whatever condition you want your views to change on inside the ListView.

    Hope it will help.

提交回复
热议问题