今天在做那个缓存处理的时候,爆出了以下异常:
在使用ViewPager时报出The application’s PagerAdapter changed the adapter’s contents without calling PagerAdapter#notifyDataSetChanged
于是我们肯定会调用adapter.notifyDataSetChanged,但是会发现,还是报出了 java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged!
当你使用ViewPager来显示网络的图片时,为了用户体验,你肯定一边下载一边更新Adapter。需要注意的是如果这个时候你的ADT版本是22以上的时候,你一定会很纠结:我明明调用了adapter.notifyDataSetChanged,但是还是报出了同样的异常提示。
在ADT22中,上面的代码肯定会报错的。原因就要看官方文档对support/v4/view/PagerAdapter的一个解释:
PagerAdapter supports data set changes. Data set changes must occur on the main thread and must end with a call to notifyDataSetChanged()
similar to AdapterView adapters derived from BaseAdapter
.
出错原因是:数据更新必须在main thread(主线程)进行更新!!!结束前还得调用notifyDataSetChanged()!!!
解决办法:
1)将你往集合里面添加数据的代码写到main thread(主线程)里面。
2)如果你使用的asynctask 那么你更新集合的代码一定不能再doInBackground方法里面。
3)如果你使用new Thread,你的更新集合的代码一定不能再run里面,要在Handler里面。
相关推荐
在重新排序之后调用了PagerAdapter的notifyDataSetChanged方法,发现ViewPager并没有更新,于是我开始跟踪源码,在调用PagerAdapter的notifyDataSetChanged方法后,会触发Viewpager的dataSetChanged方法。...
Microsoft Teams Calling Solutions 知识点 Microsoft Teams Calling Solutions 是微软公司的一项电话解决方案,旨在帮助企业和中小型企业(SMB)提高通信效率,降低成本。根据 Forrester 的研究报告,本解决方案...
HP OpenVMS Calling Standard.
bcf软件得到snp calling计算原理
SAP.Middleware.Connector.RfcCommunicationException:“destination XXXX failed when calling RFC_METADATA_GET -- see log for details” 猜测的原因: 老的DLL库在获取接口实例时,会触发“RFC_METADATA_GET”...
拉西 歌词 中日双语 calling的歌词
Descript C++ calling conventions.This is usefull for beginer.
假如一直没弄懂C/C++的呼叫惯例,那参考这份我从MSDN上特别整理的数据Calling Conventions Topics,能够很好的帮助想要对C/C++呼叫函式的方法更进一步了解的人
python库。 资源全名:joint-calling-0.1.88.tar.gz
Calling C and C++ from IDL复印版,还挺清楚的。
该文档描述了常见C++开发平台的调用约定,涉及到16位、32位、64位的程序开发,跨越Windows、Linux、BSD、Mac(基于Intel处理器)等操作系统,包含众多常用的编译器,同时文档也比较新,甚至谈论了AVX-512指令集。
an brief introduction to Wi-Fi calling
app-app-calling-android-master源码,是一个很不错的Android源码,有兴趣的伙伴们抽时间可以看一下把。
吸烟打电话训练数据集
his document contains details about data representation, function calling conventions, register usage conventions, name mangling schemes, etc.
资源分类:Python库 所属语言:Python 使用前提:需要解压 资源全名:joint_calling-0.1.49-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
T.O.T.S.S02.1080p.HULU.WEBRip.DDP5.1.x264 Pip the penguin and Freddy the flamingo become the first non-stork employees for T.O.T.S (Tiny Ones Transport Service) who deliver babies to their parents. ...
app-app-calling-android, 使用本教程构建应用Android调用应用程序的应用程序 #Build 一个简单的Android VoIP呼叫应用程序,带有 Sinch本教程将指导你构建一个简单的Android VoIP呼叫应用程序。 完成后,它将显示...
Calling R from Java java调用R java call R
It's obvious you don't know squat about calling C programs from IDL. Who does? IDL 中引用c++程序的方法