Android ListView with multiple layouts

前端 未结 3 627
清酒与你
清酒与你 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:41

    You can do that by overriding the Methods getViewCount() and getItemViewType(int position)

    In the first you just return the amount of different Views you have.

    In the second you return a unique Identifier for each different View.

    In your getView() Method you check then for the View Type and inflate the right Layout for it.

    More info about that topic: Android ListView with different layouts for each row

    Android ListView with different layouts for each row

提交回复
热议问题