I have an ExpandableListView, where every group has one child. Every child is another ListView with different number of rows. There is a problem with ExpandableListView item height in expanded condition, it's not wraping to child ListView content. I just can set a concrete height value in child listview layout. But i want to get an ExpandableListView automatically wrap every child. Is it possible?
getChildView(
) from my ExpandableListAdapter
:
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if( convertView == null ) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
convertView = inflater.inflate( R.layout.anit_object_data, parent, false );
}
ListView lv = (ListView)convertView.findViewById( R.id.listData );
List<ListData> valuesList = getItems().get(groupPosition).getListData( getContext() );
ListDataAdapter adapter = new ListDataAdapter( getContext(), android.R.layout.simple_list_item_1, valuesList );
lv.setAdapter(adapter);
return convertView;
}
XML for child ListView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id = "@+id/listHolder"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="40dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="horizontal" >
<ListView
android:id="@+id/listData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:scrollbars="none" >
</ListView>
</LinearLayout>
</LinearLayout>
I was trying to measure child ListView height in getChildView() of adapter, but ExpandableListView expanded item height is still incorrect.
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if( convertView == null ) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
convertView = inflater.inflate( R.layout.anit_object_data, parent, false );
}
ListView lv = (ListView)convertView.findViewById( R.id.listData );
List<ListData> valuesList = getItems().get(groupPosition).getListData( getContext() );
ListDataAdapter adapter = new ListDataAdapter( getContext(), android.R.layout.simple_list_item_1, valuesList );
lv.setAdapter(adapter);
lv.measure( MeasureSpec.EXACTLY, MeasureSpec.UNSPECIFIED );
convertView.getLayoutParams().height = lv.getMeasuredHeight();
return convertView;
}