2

すべてのグループに 1 つの子がある ExpandableListView があります。すべての子は、行数が異なる別の ListView です。展開された状態の ExpandableListView アイテムの高さに問題があり、子の ListView コンテンツにラップされません。子リストビュー レイアウトで具体的な高さの値を設定できます。しかし、すべての子を自動的にラップする ExpandableListView を取得したいと考えています。出来ますか?

getChildView() から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;
}


子 ListView の XML:

<?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>



アダプターの getChildView() で子 ListView の高さを測定しようとしましたが、 ExpandableListView の展開されたアイテムの高さはまだ正しくありません。

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;
}
4

2 に答える 2

1

t need a listview inside the expandablelist, it子の位置のインフレを自分で制御することはできません。他のリストを渡して子の位置を取るだけです。

于 2014-09-12T16:06:51.113 に答える
1

そうですね,グループの子ビューがリストビューだったことを確認しました。しかし、結果は良くありませんでした。子ビュー(リストビュー)の高さを測定するのが難しかったので、通常の方法で解決策を変更しました。子ビューは、リストビューのアイテムと同じようなアイテムでした。getChildView() メソッドもオーバーライドするようにします。

于 2013-05-22T15:05:43.053 に答える