0

我使用 aListView作为 a 中的子行,ExpandableListActivity并为它定义了一个自定义CursorTreeAdapter。正如预期的那样,我的代码正在填充值和视图,但是每个可扩展列表行(ListView其中包含可变数量的项目)仅部分显示(仅显示前 2 个项目)。

  1. 通过代码进行调试时,我确认所有子行 ( ListView) 都已正确填充(即其中包含 10-15 行)

  2. 为了进一步确认,我更改android:stackFromBottom = "true"ListView,这次只为每个可扩展项目行显示最后 2 个项目。

`

public class WorkExpandableListAdapter extends CursorTreeAdapter {

public WorkExpandableListAdapter(Cursor cursor, Context context) { super(cursor, context, true); }

 protected Cursor getChildrenCursor(Cursor groupCursor) { ... return childCursor; }

 @Override
 protected void bindChildView(View view, Context context, Cursor cursor,
   boolean isLastChild) {

  if (!noColumnsToDisplay) {
   int numColumns = workProjection.length + 1; // to skip the _id
   ArrayList<JXTField> jxtFields = new ArrayList<JXTField>();
   for (int i = 1; i < numColumns; i++) {
    jxtFields.add(new JXTField(workProjection[i - 1],
      cursor.getString(cursor
        .getColumnIndex(workProjection[i - 1]))));
   }

//OrderAdapter is simply a customized Array adapter which converts name value pairs into //customized 2 line items

   ArrayAdapter<JXTField> adapter = new OrderAdapter(WorkList.this,
     R.layout.work_view_row, jxtFields);
   ((ListView) view.findViewById(R.id.expandable_child_list))
     .setAdapter(adapter);
  }
 }

 @Override
public View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) {
  return getLayoutInflater().inflate(R.layout.expandable_child_list,null); }

 @Override
protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) { ... }

 @Override
 protected View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent) {
  return ((TextView) getLayoutInflater().inflate(android.R.layout.simple_expandable_list_item_1, null));
 }
}

`

expandable_child_list.xml

`

<ListView 
    android:id="@+id/expandable_child_listt"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:paddingLeft="20dp"      
    android:layout_weight="2.0"     
    />

`

work_view_row.xml `

<LinearLayout
    android:orientation="vertical"
    android:layout_width="0dip"
    android:layout_weight="1"
    android:layout_height="fill_parent">

    <TextView
        android:id="@+id/work_view_row_top_text"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:gravity="center_vertical"
    />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1" 
        android:id="@+id/work_view_row_bottom_text"
        android:ellipsize="marquee"
        android:textAppearance="?android:attr/textAppearanceMedium"
    />

</LinearLayout>

`

当我第一次遇到它时,这看起来很容易解决,但是在浪费了太多时间之后,我求助于大师。也许我遗漏了一些非常明显的东西,但请指出。:(

提前致谢。

4

1 回答 1

0

我能够通过使用ListView覆盖的子类来解决问题onMeasure()

以下 2 篇文章非常有助于为我指明正确的方向。
1.如何创建不在 ScrollView 中或禁用 ScrollView 的 ListView?
2.计算列表视图的大小或如何告诉它完全展开

但是,我仍然觉得这是一个臃肿的工作,并且不知道为什么返回的视图newChildView()不允许ListView完全扩展,即使android:layout_height="fill_parent"ListView及其容器 ( LinearLayout) 设置。

如果有人能指出原因,那就太好了。
谢谢你。

于 2010-12-29T23:41:23.693 回答