PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged

本文解决了PagerAdapter在更新数据后未调用notifyDataSetChanged()导致的异常问题。关键在于每次更改数据后必须调用此方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天开发的时候遇到了如题的异常。上网搜到了个答案:

After ADT 22 the PagerAdapter has gotten very strict about calling notifyDataSetChanged() before calling getCount().  It evidently keeps track of what it thinks the count should be and if this is not the same as what getCount() returns it throws this exception.  So the solution is simply to call notifyDataSetChanged() on the adapter every time the size of the data changes.

解决办法就是必须要在对adapter的data做改变之后马上调用notifyDataSetChanged()。搜索了代码,确实发现有没有调用的地方。改了就好了。

转载于:https://my.oschina.net/u/268088/blog/789742

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值