Recycleview 使用中的问题
2016-05-23 19:48
369 查看
1.使用Recycleview notifyDataSetChanged() IllegalStateException
解决:public void onBindViewHolder(final ViewHolder holder, final int position) {
SwitchCompat mySwitch = (SwitchCompat) view.findViewById(R.id.switch);
//Set it to null to erase an existing listener from a recycled view.
mySwitch.setOnCheckedChangeListener(null);
}`
解决:public void onBindViewHolder(final ViewHolder holder, final int position) {
SwitchCompat mySwitch = (SwitchCompat) view.findViewById(R.id.switch);
//Set it to null to erase an existing listener from a recycled view.
mySwitch.setOnCheckedChangeListener(null);
//Set the switch to how it previously was without triggering the listener. mySwitch.setChecked(savedSwitchState); //If the saved state was "true", then this will trigger the infinite loop. //Set the listener now. mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { data.delete(position); notifyItemRemoved(position); //This will call onBindViewHolder, but we can't do that when we are already in onBindViewHolder! notifyItemRangeChanged(position, data.size()); } } });
}`
相关文章推荐
- 《学习笔记》之JAVA设计模式--原型模式
- 成为程序员的一些基本"法则"
- 百度地图--定位
- BZOJ 1088 枚举 + 推
- 阅读程序(3)
- Struts2国际化
- Tomcat 的运行机制
- WebView实现html文件选择(input type=file),兼容安卓6.0
- <OJ_Sicily>DAG
- Scala正则使用
- HBase简介(很好的梳理资料)
- Android开发实践 网络通信 URL、URLConnection、HttpClient
- 剑指Offer——表示数值的字符串
- 昂贵的聘礼 最短路 dijkstra
- 第10章 C# 数据库编程技术
- 【Arduino官方教程第零辑】基础部分 1-3 Arduino软件(IDE)
- 第十三周项目54-交通工具类
- leetcode 202 Happy Number C++
- Struts2 Unexpected Exception提交表单控制台报Exception
- java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com