最近在做的新闻客户端用到了ViewPager,Android Studio如今集成的很好了,自动创建很多不必要写的代码。在使用过程中碰到了一个很奇怪的事:ViewPager中加载的数据重复具体的看图就明白了: 可以看到加载出来的数据,1、2页面出现了重复,而3恢复正常在 ...
最近在做的新闻客户端用到了ViewPager,Android Studio如今集成的很好了,自动创建很多不必要写的代码。
在使用过程中碰到了一个很奇怪的事:ViewPager中加载的数据重复
具体的看图就明白了:
可以看到加载出来的数据,1、2页面出现了重复,而3恢复正常
在困扰许久之后博主在stackoverflow上面找到了大神的解答:
Because you ware using static variable to show in fragments.When your say static its not a part of the class instance it creates only once and shared among the multiple fragment instance. And you ware changing it in getItem() method , as it is static was reflecting in all fragment instance and repeating.
原标题:Android ViewPager 重复数据问题的解决方法
关键词:Android
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。