android ScrollView嵌套ListView adapter的notifyDataSetChanged无效
来源:互联网 发布:java源代码文件调试 编辑:程序博客网 时间:2024/06/04 23:31
首先,notifyDataSetChanged方法无效,一般是:
1、数据源没有更新,调用notifyDataSetChanged无效。
2、数据源更新了,但是它指向新的引用,调用notifyDataSetChanged无效。
3、数据源更新了,但是adpter没有收到消息通知,无法动态更新列表。
说一个典型的例子:
ArrayList list = new ArrayList();adapter实例化使用上边的list,如果数据变化,list=newDataList,然后调用notifyDataSetChanged,无效,因为指向了新的引用,一般讲老的list清空,再重新赋值,list.clear();list.addAll(newlist);adapter.notifyDataSetChanged();会有效
问题是,ScrollView嵌套ListView,为了防止ListView只显示一行,会使用以下方法
//解决ScrollView嵌套ListView只显示一行 public void setListViewHeightBasedOnChildren(ListView listView) { // 获取ListView对应的Adapter ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return; } int totalHeight = 0; for (int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目 View listItem = listAdapter.getView(i, null, listView); // 计算子项View 的宽高 listItem.measure(0, 0); // 统计所有子项的总高度 totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); // listView.getDividerHeight()获取子项间分隔符占用的高度 // params.height最后得到整个ListView完整显示需要的高度 listView.setLayoutParams(params); }
如果使用这个方法,又要notifyDataSetChanged有效,应该在notifyDataSetChanged后边调用该方法
adapterList.clear(); adapterList.addAll(data.getRstData().get(0).getPeriodVOList()); orderSelectTimeAdapter.notifyDataSetChanged();setListViewHeightBasedOnChildren(list);
0 0
- android ScrollView嵌套ListView adapter的notifyDataSetChanged无效
- Android adapter.notifyDataSetChanged无效
- adapter的notifyDataSetChanged()无效
- listview 嵌套gridview notifyDataSetChanged无效
- Android记录15--关于ListView中adapter调用notifyDataSetChanged无效的原因
- Android记录15--关于ListView中adapter调用notifyDataSetChanged无效的原因
- 关于ListView中adapter调用notifyDataSetChanged无效的原因
- ListView中adapter调用notifyDataSetChanged无效的原因
- android adapter 调用notifyDataSetChanged 无效
- adapter的notifyDataSetChanged()无效
- Xamarin.Android Adapter NotifyDataSetChanged无效问题
- android中adapter使用notifydatasetchanged无效
- Android listView 的适配器adapter.notifyDataSetChanged();刷新没有作用
- android ScrollView嵌套ListView
- android ScrollView嵌套ListView
- android ScrollView嵌套Listview
- android scrollview 嵌套listview
- Android ScrollView嵌套ListView
- java集合类详解
- canvas中save和restore
- duilib bkimage属性说明
- Android支持多国语言
- 一个简单实用的程序员鸡汤
- android ScrollView嵌套ListView adapter的notifyDataSetChanged无效
- GDAL——生成等值线
- 【ADF启动start server instance失败】
- 原生ajax POST,解决Undefined index
- ApplicationContext
- Java打印常见图形
- UVA455
- jQuery知识结构图
- C++ 引用 “&”