时间:2021-05-19
正文
首先是最基础的
ExpandableListView vList = (ExpandableListView) this.findViewById(R.id.list);EListAdapter adapter = new EListAdapter(getApplicationContext(), list); //list 是数据源vList.setAdapter(adapter);//适配器就不写了, 都懂的class EListAdapter extends BaseExpandableListAdapter {}一般情况下, ListView是使用notifyDataSetChanged() 更新的
adapter.notifyDataSetChanged();
ExpandableListView 也是ListView, 估计这样是可以的.
可惜现在用的不是ListView, 而是ExpandableListView! 所以报错了0. 0
Java.lang.ClassCastException: Android.widget.ExpandableListConnector
在Google 找了资料, 发现是很多都犯这个错误. 解决方法也蛮简单的!
class EListAdapter extends BaseExpandableListAdapter { public EListAdapter(Context context, List<T> list) { this.list = list; this.context = context; handler = new Handler(){ @Override public void handleMessage(Message msg) { notifyDataSetChanged(); super.handleMessage(msg); } }; } public void refresh() { handler.sendMessage(new Message()); }}只要我们调用refresh() 方法就可以使用notifyDataSetChanged() 了.
可是!! 只有GroupView 更新!!
ChildView 没有更新! 惨了....要更新的在ChildView!!
继续靠Google 娘! 大家都提供很多方法, 有一个人说, 直接在list 添加item 再更新就可以了!
我试了一下,没有任何效果.......
查了一查SDK 文档, 发现Group 的伸缩会引起getChildView(int, int, boolean, View, ViewGroup) 的运行!
所以刷新的ChildView 的方法很简单.
只有伸缩一次就可以了! 连Adapter 都不用重写! 简单吧?
vList.collapseGroup(groupPosition);vList.expandGroup(groupPosition);以上就是小编为大家带来的Android 关于ExpandableListView刷新问题的解决方法全部内容了,希望大家多多支持~
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
Android中SwipeRefreshLayout与ViewPager滑动事件冲突解决方法问题描述:开发中发现,SwipeRefreshLayout的下拉刷新
AndroidScrollView嵌套ExpandableListView显示不正常的问题的解决办法前言:关于ScrollView嵌套ExpandableLis
本文实例讲述了Android中ExpandableListView的用法,ExpandableListView是android中可以实现下拉list的一个控件,
Android7.0行为变更FileUriExposedException解决方法当我们开发关于【在应用间共享文件】相关功能的时候,在Android7.0上经常
今天给大家讲讲android的目录实现方法,就像大家看到的小说目录一样,android提供了ExpandableListView控件可以实现二级列表展示效果,现