【问题标题】:ExpandableListAdapter in a DialogPreferenceDialogPreference 中的 ExpandableListAdapter
【发布时间】:2013-03-25 12:28:05
【问题描述】:

我正在尝试将 ExpandableListAdapter 添加到 DialogPrefence。

我的布局

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

这就是我使用 ListView 的方式

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

我必须如何使用 ExpandableListAdapter?

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

这会导致:

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

【问题讨论】:

    标签: android android-layout expandablelistview expandablelistadapter


    【解决方案1】:

    ExpandableListView 调用setAdapter(ExpandableListAdapter),而不是从AbsListView 调用通用setAdapter(ListAdapter)

    即改变

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

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

    【讨论】:

    • 你知道是否可以让它们默认展开?
    • @Harry,你是什么意思?在你想默认扩展的组上调用expandGroup()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    相关资源
    最近更新 更多