Getting the ID in a list of fragments in a PagerActivity
-
28-10-2019 - |
Question
I have a working PagerActivity (extends FragmentActivity) with a bunch of Fragment objects in it. Everything works fine but what I want to do now is to display the number of the Fragment in the list (let's say there are 25 Fragment objects and I want to display the current number in that list of Fragments).
How can I do that? Is there some method I can call in the Fragment object?
I'm filling the PagerAdapter like this (snippet):
fragments = new Vector<Fragment>();
for (int i = 0; i < wiList.length; i++) {
WhiteboardImage tmpWi = wiList[i];
Bundle bundle = new Bundle();
bundle.putString("wiImage", gson.toJson(tmpWi));
bundle.putInt("positionInList", positionInList);
bundle.putInt("totalCount", wiList.length);
fragments.add(Fragment.instantiate(params[0], GalleryFragment.class.getName(), bundle));
}
mPagerAdapter = new GalleryPagerAdapter(getSupportFragmentManager(), fragments);
Thanks for any help!
Solution
I assume GalleryPagerAdapter
is a FragmentViewPager
? Then the number of fragments would be fragments.size()
, no?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow