0

Im trying to add an ExpandableListAdapter to a DialogPrefence.

My layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/channels_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:orientation="horizontal" >
    <LinearLayout
        android:id="@+id/channelsProgress"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone" >

        <ProgressBar
            android:id="@+id/pbChannelsProgress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:descendantFocusability="beforeDescendants" >
        </ProgressBar>
    </LinearLayout>
    <ExpandableListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         >
    </ExpandableListView>

</LinearLayout>

This is how I did it with a ListView

HiddenChannelsListAdapter adapter = new HiddenChannelsListAdapter(ctx, tree, subscribed_channelsList);
ListView lv = (ListView) vw.findViewById(R.id.list);
lv.setAdapter(adapter);

How must I do it with a ExpandableListAdapter?

ExampleReallySimpleExpandableListAdapter adapter = new ExampleReallySimpleExpandableListAdapter(ctx, groupData, childData);
AbsListView lv = (AbsListView) vw.findViewById(R.id.list);
lv.setAdapter(adapter);

This results in:

03-25 14:24:23.780: E/AndroidRuntime(22187): FATAL EXCEPTION: main
03-25 14:24:23.780: E/AndroidRuntime(22187): java.lang.ClassCastException: com.example.tvrplayer.ExampleReallySimpleExpandableListAdapter cannot be cast to android.widget.ListAdapter
4

1 に答える 1

1

Call setAdapter(ExpandableListAdapter) from ExpandableListView, not the generic setAdapter(ListAdapter) from AbsListView.

That is, change

AbsListView lv = (AbsListView) vw.findViewById(R.id.list);

to

ExpandableListView lv = (ExpandableListView) vw.findViewById(R.id.list);
于 2013-03-25T12:36:41.820 に答える