问题
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:
- Define a one row file for the list item, say for example, RelativeLayout with 2-3 TextViews.
- Define a class by extending
BaseAdapter
. - Inflate the XML and do display operations inside the
getView()
method of this class. - Set this adapter to the ListView.
来源:https://stackoverflow.com/questions/10091986/android-is-it-possible-to-put-multiple-layouts-in-listview-items