My problem
I am using a ViewPager to display fragments inside a FragmentActivity . ViewPager gets fragments from the attached FragmentPagerAdapter .
mViewPager = (ViewPager) findViewById(R.id.view_pager); mAdapter = new HomePagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(mAdapter);
Suppose the ViewPager has 3 fragments to display: Fragment1 , Fragment2 , Fragment3 . Fragment1 is a fragment of a grid and displays a grid. Fragment2 and Fragment3 have their own content to display. When the screen appears on the screen, ViewPager display the next fragment - Fragment2 . And so on.
What I need?
I want that when you click an element from the grid ( Fragment1 displayed), Fragment1 should be completely replaced with some other fragment, say Fragment4 (this is another fragment and does not return using the included adapter). The user will work with Fragment4 and after ButtonBack click (just the iside button Fragment4 ), Fragment1 with the grid should be displayed again. Meanwhile, the ViewPager should behave the same as when scrolling, the following fragment will be shown (in our case Fragment2 ).
So I just want to get the same behavior as in the example: http://developer.android.com/training/basics/fragments/fragment-ui.html#Replace
My question
So can this be achieved? If so, how? I would really appreciate your help. Alex PS Sorry for my English :)
android replace android-fragments android-viewpager fragmentpageradapter
AlexMomotov
source share