android: Is it possible to put multiple layouts in listview items

梦想与她 提交于 2020-01-17 04:33:12

问题


hi I want to use a listview (probably) is it possible to fill each entry with say two buttons two text areas, and have them laid out with realtive or linear layouts?

I have used a scroll view with layout inflator to achieve this at the moment, but I'm thinking listview would be better maybe?


回答1:


yes you can. you need to use a custom list view for that. making an activity by adding a listview in it and then referencing another xml to that listview using an AAdapter so that every element of the listview has the layout of the second xml file. this tutorial should help you understand the idea.




回答2:


Yes you can place any widgets for the particular List Item for your listview.

For defining that kind of ListView, you have to define a custom adapter, follow the below steps:

  1. Define a one row file for the list item, say for example, RelativeLayout with 2-3 TextViews.
  2. Define a class by extending BaseAdapter.
  3. Inflate the XML and do display operations inside the getView() method of this class.
  4. Set this adapter to the ListView.


来源:https://stackoverflow.com/questions/10091986/android-is-it-possible-to-put-multiple-layouts-in-listview-items

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