出处
正文
首先是最基础的
ExpandableListView vList = (ExpandableListView) this.findViewById(R.id.list); EListAdapter adapter = new EListAdapter(getApplicationContext(), list); //list 是数据源 vList.setAdapter(adapter);
一般情况下, ListView是使用notifyDataSetChanged() 更新的
adapter.notifyDataSetChanged();
ExpandableListView 也是ListView, 估计这样是可以的.可惜现在用的不是ListView, 而是ExpandableListView! 所以报错了
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()); } }
只有GroupView 更新!! ChildView 没有更新! 惨了....要更新的在ChildView!!查了一查SDK 文档, 发现Group 的伸缩会引起getChildView(int, int, boolean, View, ViewGroup) 的运行!
所以刷新的ChildView 的方法很简单. 只有伸缩一次就可以了!
vList.collapseGroup(int position); vList.expandGroup(int position);