RecyclerView---adapter.notifyDataSetChanged()不起作用
来源:互联网 发布:斑马二维码打印软件 编辑:程序博客网 时间:2024/06/01 19:30
今天在使用RecyclerView过程中adapter.notifyDataSetChanged()不起作用,通过Logcat打印发现数据源变化了,但是视图一直没变,后面发现是list集合在内存中的地址变了。
之前的写法是:
JsonObject jsonObject = new JsonParser().parse(msg.obj.toString()).getAsJsonObject();if (jsonObject.get("success").getAsBoolean()) { jsonArray = jsonObject.get("data").getAsJsonObject().get("list").getAsJsonArray(); collectionRecyclerAdapter.notifyDataSetChanged(); LogUtils.e("snotifyDataSetChanged时jsonArray的地址: " + jsonArray.hashCode());} else { ToastUtils.showShort(mContext, "您还没有收藏任何文章");}
collectionRecyclerAdapter.notifyDataSetChanged();//调用此方法界面不刷新
这里数据源jsonArray确实变了,但这种重新赋值的方式让该集合在内存中的地址也变了,所以adapter会认为原数据源没变
JsonObject jsonObject = new JsonParser().parse(msg.obj.toString()).getAsJsonObject();if (jsonObject.get("success").getAsBoolean()) { JsonArray jsonArray1 = jsonObject.get("data").getAsJsonObject().get("list").getAsJsonArray(); jsonArray.addAll(jsonArray1); collectionRecyclerAdapter.notifyDataSetChanged(); LogUtils.e("snotifyDataSetChanged时jsonArray的地址: " + jsonArray.hashCode());} else { ToastUtils.showShort(mContext, "您还没有收藏任何文章");}
collectionRecyclerAdapter.notifyDataSetChanged();//调用此方法界面成功刷新这里新创建了一个数据类作为中间容器存储获取到的数据,然后再调用jsonArray.add()方法,这种形式原数据源的内存地址没有改变,所以adapter.notifyDataSetChanged()就会起作用。
阅读全文
0 0
- RecyclerView.Adapter notifyDataSetChanged 不起作用
- RecyclerView.Adapter notifyDataSetChanged 不起作用
- RecyclerView.Adapter notifyDataSetChanged 不起作用
- RecyclerView---adapter.notifyDataSetChanged()不起作用
- Android问题集-RecyclerView---adapter.notifyDataSetChanged()不起作用
- 开发遇到的坑:RecyclerView.Adapter notifyDataSetChanged 不起作用
- adapter.notifyDataSetChanged()不起作用
- adapter.notifyDataSetChanged()刷新不起作用
- RecyclerView notifyDataSetChanged不起作用
- adapter.notifyDataSetChanged()不起作用的解决
- android adapter的notifyDataSetChanged不起作用
- Android 解决 adapter.notifyDataSetChanged() 不起作用
- RecyclerView.Adapter notifyDataSetChanged 无效问题
- 为什么我的adapter.notifyDataSetChanged()不起作用?
- RecyclerView 中adapter.notifyDataSetChanged()无效的问题
- 自定义adapter 改变数据后调用notifyDataSetChanged() 不起作用的解决方法
- 关于Android 适配器adapter.notifyDataSetChanged()不起作用的原因
- notifyDataSetChanged不起作用
- QTP11的下载地址和破解教程
- 1像素Activity进程保活
- jQuery使用最广泛的javascript函数库
- Java线程:Callable和Future
- iOS中常见的几种函数(向上,向下,四舍五入)
- RecyclerView---adapter.notifyDataSetChanged()不起作用
- ElasticSearch Yellow status d
- druid连接池
- error MSB6006: “cmd.exe”已退出,代码为1
- Android XListView下拉刷新和上拉加载更多
- c/c++ curl smtp 发送邮件太长导致段错误的问题
- 滴滴插件化开源virtual apk开源,实现插件和宿主资源互访
- Hibernate 优化技术之调用视图(View)和存储过程(Procedure)
- 《拒绝平庸》读后感,勉励自己