【问题标题】:ExpandableListView with two TextViews per ItemExpandableListView,每个项目有两个 TextView
【发布时间】:2012-05-20 19:58:01
【问题描述】:

是否可以在 ExpandableListView 的项目中放置多个 TextView? 我试过这个,但不工作,第二台电视没有显示:

group_item.xml

<TextView android:id="@+id/row_name"
     android:paddingLeft="5dp"
     android:textSize="18dp"
     android:textColor="@color/black"
     android:textStyle="normal"
     android:layout_width="320dp"
     android:layout_height="wrap_content"/>

<TextView android:id="@+id/row_desc"
    android:text="Some text here"
     android:paddingLeft="5dp"
     android:textSize="18dp"
     android:textColor="@color/black"
     android:textStyle="normal"
     android:layout_width="320dp"
     android:layout_height="wrap_content"/>

【问题讨论】:

  • 你可以把任何你想要的作为ListView项,你是如何设置适配器的?你的完整 group_item.xml 是什么?
  • 您是否将其添加到您的适配器调用中?您使用的是数组还是游标?需要更多信息。编辑问题并至少发布您调用 ExpandableListView 适配器和适配器本身的问题。

标签: android listview textview expandablelistview


【解决方案1】:

你还没有说是什么支持你的列表视图,所以我将展示一个带有光标的示例(假设是 SimpleCursorTreeAdapter)。

mAdapter = new MyExpandableListAdapter(
    mGroupsCursor,                                  // cursor supplying group data
    getActivity(),                                  // context
    R.layout.group_item,                            // Group row layout
    R.layout.child_item,                            // Child row layout
    new String[] { "column1", "column2" },          // Cursor columns from group cursorto be mapped to group view
    new int[] { R.id.row_name, R.id.row_desc },     // View ids to receive group column data
    new String[] { "child1", "child2"},             // Cursor columns from child cursor to be mapped to child view
    new int[] { R.id.child1, R.id.child2            // View ids to receive child column data
});    
lv.setAdapter(mAdapter);                        // Set your adapter

【讨论】:

    【解决方案2】:

    是的,这是可能的。但是您必须自己进行绑定。因此制作一个自定义适配器并覆盖 bindGroupView 或 bindChildView 方法。

    -编辑-

    对不起,我对这个问题有点困惑。如果您只想填充两个文本视图,那么您不必覆盖 bindgroupview 或 bindchildview 方法。仅当您需要进行更复杂的绑定时。

    【讨论】:

      【解决方案3】:

      是的,我添加到 github 中可能会为您提供一个示例。

      我正在这个项目中处理冻结列 exp。别理他们。在适配器中,您将看到多个列

      https://github.com/huseyinDaVinci/Android/tree/master/ExpandableListView

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-22
        • 1970-01-01
        • 1970-01-01
        • 2012-04-16
        相关资源
        最近更新 更多