Android的 - 多列的ListView [英] Android - Multi Columns ListView

查看:187
本文介绍了Android的 - 多列的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ArrayList< myObject的> 的ListView 与个人 ArrayAdapter< myObject的> 使用充气查看生成的列表按钮取值

I have an ArrayList<myObject> and a ListView with a personal ArrayAdapter<myObject> using an inflated View that generates a list of Buttons.

它的工作原理,但每行一个按钮布局相当耗费^^

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 for a better user experience...

什么想法?或对象,已经实现了吗?

any idea ? or object that already implements it ?

感谢

推荐答案

有关这种情况下,只需要2列的GridView,我相信这将满足您的要求。

For that case, just take a GridView with 2 columns, i am sure this will fulfill your requirement.

gridview_row.xml
    
    

gridview_row.xml

    <Button 
        android:text="Button" 
        android:id="@+id/button1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
    </Button>

</LinearLayout>

和采取的ListView GridView的instad为:

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>

一旦你与​​这些两件事情做了,那么执行code在自定义的适配器。我相信您当前的适配器也是90%是有用的,你只需要根据该行的xml文件来改变code。

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.

这篇关于Android的 - 多列的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆