Android ListView with different layouts for each row

前端 未结 6 1560
独厮守ぢ
独厮守ぢ 2020-11-21 07:09

I am trying to determine the best way to have a single ListView that contains different layouts for each row. I know how to create a custom row + custom array adapter to sup

6条回答
  •  爱一瞬间的悲伤
    2020-11-21 08:12

    In your custom array adapter, you override the getView() method, as you presumably familiar with. Then all you have to do is use a switch statement or an if statement to return a certain custom View depending on the position argument passed to the getView method. Android is clever in that it will only give you a convertView of the appropriate type for your position/row; you do not need to check it is of the correct type. You can help Android with this by overriding the getItemViewType() and getViewTypeCount() methods appropriately.

提交回复
热议问题