aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/activity
diff options
context:
space:
mode:
authorcampbeb <bpcampbell@gmail.com>2013-06-12 21:45:08 -1000
committercampbeb <bpcampbell@gmail.com>2013-06-12 21:45:08 -1000
commit467553482f50179f1f1d4fa806f23e00778264d2 (patch)
treeb21e4f2c9f70f1a737d579863199ac06cee5297b /main/src/cgeo/geocaching/activity
parentcf839616a5a195052ea602ecf7abf14209c8a980 (diff)
downloadcgeo-467553482f50179f1f1d4fa806f23e00778264d2.zip
cgeo-467553482f50179f1f1d4fa806f23e00778264d2.tar.gz
cgeo-467553482f50179f1f1d4fa806f23e00778264d2.tar.bz2
ViewPager - Notify when contents of adapter change
Some missing calls to notifyDataSetChanged discovered when testing latest version of support library
Diffstat (limited to 'main/src/cgeo/geocaching/activity')
-rw-r--r--main/src/cgeo/geocaching/activity/AbstractViewPagerActivity.java13
1 files changed, 9 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/activity/AbstractViewPagerActivity.java b/main/src/cgeo/geocaching/activity/AbstractViewPagerActivity.java
index e0c304a..0345633 100644
--- a/main/src/cgeo/geocaching/activity/AbstractViewPagerActivity.java
+++ b/main/src/cgeo/geocaching/activity/AbstractViewPagerActivity.java
@@ -208,6 +208,7 @@ public abstract class AbstractViewPagerActivity<Page extends Enum<Page>> extends
pageOrder.add(null);
}
}
+ viewPagerAdapter.notifyDataSetChanged();
viewPager.setCurrentItem(startPageIndex, false);
}
@@ -233,15 +234,19 @@ public abstract class AbstractViewPagerActivity<Page extends Enum<Page>> extends
final Pair<List<? extends Page>, Integer> pagesAndIndex = getOrderedPages();
pageOrder.addAll(pagesAndIndex.getLeft());
+ // Since we just added pages notifyDataSetChanged needs to be called before we possibly setCurrentItem below.
+ // But, calling it will reset current item and we won't be able to tell if we would have been out of bounds
+ final int currentItem = getCurrentItem();
+
+ // notify the adapter that the data has changed
+ viewPagerAdapter.notifyDataSetChanged();
+
// switch to details page, if we're out of bounds
final int defaultPage = pagesAndIndex.getRight();
- if (getCurrentItem() < 0 || getCurrentItem() >= viewPagerAdapter.getCount()) {
+ if (currentItem < 0 || currentItem >= viewPagerAdapter.getCount()) {
viewPager.setCurrentItem(defaultPage, false);
}
- // notify the adapter that the data has changed
- viewPagerAdapter.notifyDataSetChanged();
-
// notify the indicator that the data has changed
titleIndicator.notifyDataSetChanged();
}