ListView Adapter with multiple Item layouts

青春壹個敷衍的年華 提交于 2019-12-06 13:06:27

Do you really want separate .xml files? Or do you want to reuse one .xml file and just replace its content?

If you want separate .xml files (meaning multiple different Views in your Adapter) take a look at the Adapters methods:

  • getViewTypeCount() - returns how many different view layouts you have
  • getItemViewType(int pos) - returns correct view type id by position

With these methods you can specify the number of different types in your adapter, and load different layout files depending on the type.

You could for example have an Adapter like this supporting multiple layouts. (e.g. one item being an actual item, the other one being a separator between the items)

For more specific information, please take a look at this great tutorial:

http://android.amberfog.com/?p=296

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!