Android - Multi Columns ListView
I have an ArrayList<myObject>
and a ListView
with a personal ArrayAdapter<myObject>
using an inflated View that generates a list of Button
s.
It works, but one button per line is quite layout consuming ^^
I wanted to know if it was possible to display two or more items (Button) per line and how to do such a thing ?
I thought about dividing my items in two lists (even and odd) but they'll have to scroll all-together fo开发者_如何学编程r a better user experience...
any idea ? or object that already implements it ?
Thanks
For that case, just take a GridView with 2 columns, i am sure this will fulfill your requirement.
gridview_row.xml
<Button
android:text="Button"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</LinearLayout>
and take GridView instad of ListView as:
<GridView
android:id="@+id/gridview01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="2"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp">
</GridView>
Once you are done with these 2 things, then implement the code in your custom adapter. And i am sure your current adapter is also 90% useful, you just need to change the code according the row xml file.
精彩评论