Maybe the title of the question is common, but that is not the problem. I use one action in which the frame layout I replace the fragment FragmentTransactionand FragmentManager. this is done successfully, I got a new fragment, say, fragment A. Now in fragment A I have viewpagerthree tabs, and each tab has fragment, so in fragment A I have fragment B, fragment C and fragment D.
The entire Activity-> script replacing framelayout → Fragment A-> three tabs (three fragments of fragment B, fragment C and fragment D)
Now the Problem :
When I am on the second tab, if I return, I will immediately proceed to activity. I want to do if in the second or third tab go to the previous tabs, and if in the first tab go to the activity page.
Maybe the backtrace fragment is automatically maintaned, but if it is used only in Activity, then only. right now i'm using snippet to hold tabs.
What I tried:
I created a listener:
PageChangeListener:
public interface PageChangeListener {
public void onNextRequest();
public void onPrivousRequest();
}
This is implemented in fragment A:
@Override
public void onNextRequest() {
if(mViewPagerPage + 1 < mPageCount)
{
viewPager.setCurrentItem(++mViewPagerPage,true);
}
}
@Override
public void onPrivousRequest() {
if(mViewPagerPage -1 >= 0)
{
viewPager.setCurrentItem(--mViewPagerPage,true);
}
}
But in this task there is: where to use the onPrivousRequest () method, since fragments do not have the onBackPressed method.
Any help would be appreciated.