简单问题: 我想知道在展开可扩展列表视图时是否可以每行包含两个项目。
如果是 - >怎么样?
如果没有 - > :(
THX
答案 0 :(得分:0)
我不知道是否有针对此的特定库,但我认为您只需使用自定义行布局创建自定义适配器,并将每行填充两个而不是一个。
示例:
行-布局:
<LinearLayout
android:width="match-parent"
android:height="wrap-content"
android:orientation="vertical">
<TextView android:id="@+id/first"
android:width="match-parent"
android:height="wrap-content"/>
<TextView android:id="@+id/second"
android:width="match-parent"
android:height="wrap-content"/>
</LinearLayout>
和适配器类似:
private ArrayList<MyItems> myItems; //fill this with the constructor
@Override
public View getView(int position, View v, ViewGroup vg)
{
//initialize the layout inflater and other stuffs like textviews
if(position % 2 == 0){
//this is because you are grouping items by 2, so you only consider the first of the couple.
textView1.setText(myItems.get(position).getText());
textView2.setText(myItems.get(position+1).getText());
//here tou can manage also the onclicklisteners for each item
}
}
这是一个想法,告诉我这是否可行。
PS:我在这里手写这个,所以可能会有一些写错误,在这种情况下可以自由编辑答案:)