首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DialogPreference中的ExpandableListAdapter

DialogPreference中的ExpandableListAdapter
EN

Stack Overflow用户
提问于 2013-03-25 20:28:05
回答 1查看 236关注 0票数 0

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

我的布局

代码语言:javascript
复制
<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实现的方法

代码语言:javascript
复制
HiddenChannelsListAdapter adapter = new HiddenChannelsListAdapter(ctx, tree, subscribed_channelsList);
ListView lv = (ListView) vw.findViewById(R.id.list);
lv.setAdapter(adapter);

我必须如何使用ExpandableListAdapter来完成此操作?

代码语言:javascript
复制
ExampleReallySimpleExpandableListAdapter adapter = new ExampleReallySimpleExpandableListAdapter(ctx, groupData, childData);
AbsListView lv = (AbsListView) vw.findViewById(R.id.list);
lv.setAdapter(adapter);

这将导致:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-25 20:36:42

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

也就是说,改变

代码语言:javascript
复制
AbsListView lv = (AbsListView) vw.findViewById(R.id.list);

代码语言:javascript
复制
ExpandableListView lv = (ExpandableListView) vw.findViewById(R.id.list);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15614957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档