My ListView has two types of views. How to manage?

前端 未结 1 538
不思量自难忘°
不思量自难忘° 2021-01-15 22:19

My events management app has two types of views in the list view : a small simmple text view for not-so-important events and a complex view created with a FrameLayout

相关标签:
1条回答
  • 2021-01-15 23:11

    Due to the view recycling in Android, it may happen that the convertView returned to me is recycled from the simpler view and I now have to display the larger view.

    Not if you override getViewTypeCount() and getItemViewType() in your adapter.

    In your case:

    • getViewTypeCount() would return 2

    • getItemViewType() would return 0 or 1, where you return 0 for those positions that are one type of row, and return 1 for those positions that return the other type of row

    Then, you are guaranteed that if convertView is not null, it is a row of the proper type.

    0 讨论(0)
提交回复
热议问题