问题所在:我们在数据源发生改变时,调用notifyDataSetChanged() 方法,发现界面没有变化
原因分析:
追踪到ViewPager 的 dataSetChanged()方法,此方法用于刷新界面,看看具体的实现:
...
for (int i = 0; i < mItems.size(); i++) {
final ItemInfo ii = mItems.get(i);
final int newPos = mAdapter.getItemPosition(ii.object);
if (newPos == PagerAdapter.POSITION_UNCHANGED) {
continue;
}
if (newPos == PagerAdapter.POSITION_NONE) {
...
continue;
}
...
}
...
官方给出了解释:
Called when the host view is attempting to determine if an item’s position has changed. Returns POSITION_UNCHANGED if the position of the given item has not changed or POSITION_NONE if the item is no longer present in the adapter.The default implementation assumes that items will never change