0

I use a ListView as the child row in a ExpandableListActivity and have defined a custom CursorTreeAdapter for it. The values and the views are being populated by my code just as expected, but each expandable list row (ListView with variable number of items in it) is only partially shown (only the first 2 items are being displayed).

  1. While debugging through the code, I confirmed that all the child rows (ListView) are being populated properly (that is with 10-15 rows in it)

  2. Just to confirm further, I changed android:stackFromBottom = "true" for the ListView, this time only the last 2 items were displayed for each expandable item row.

`

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>

`

This looked like an easy one to solve when I first encountered it, but after wasting too much time on it I resort to the gurus. Maybe I am missing something very obvious, but please point out. :(

Thanks in advance.

Philipp Reichart
  • 20,771
  • 6
  • 58
  • 65
ritwaj
  • 15
  • 1
  • 6

1 Answers1

0

I was able to solve the problem by using a subclassed ListView which overrides onMeasure().

The following 2 posts were very helpful in pointing me in the right direction.
1. How do I create a ListView that's not in a ScrollView, or has the ScrollView disabled?
2. Calculate the size of a list view or how to tell it to fully expand

However, I still feel this was a bloated work around, and have no idea why the view returned by newChildView() does not allow ListView to expand fully even when android:layout_height="fill_parent" is set for the ListView and its container (LinearLayout).

It would be great, if someone can point out the reason.
Thank you.

Community
  • 1
  • 1
ritwaj
  • 15
  • 1
  • 6