每当我通过标签栏动作导航到片段时,如何重置片段的状态。 例如:我有两个TABS(A和B),每个都有3个片段。 目前,我在标签B的片段3中。 - 我选择标签A. - 我选择标签B 预期结果应该是相应标签(B)的片段编号1。 它实际上是什么,它将我带到以前保存的状态,即片段3。
toolBarTextView = (TextView) findViewById(R.id.toolBarTextView);
viewPager = (ViewPager) findViewById(R.id.pager);
adapter = new ViewPagerAdapter(getSupportFragmentManager());
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
// Add Fragments to adapter one by one -- For TAB 1
if (fragmentNo != 1){
adapter.addFragment(new OpenOrdersFragment(),"0\nOPEN");
}else if (fragmentNo == 1){
//from OpenOrdersFragment fragment to move in BookingDetailFragment
adapter.addFragment(new BookingDetailFragment(),"0\nOPEN");
}
//from assigned fragment to move in BookingDetailFragment -- For TAB 2
if (fragmentNo == 0 || fragmentNo == 1 || fragmentNo == 2){
//adapter.addFragment(new BookingAssigned(),"0\nASSIGNED");
} else if (fragmentNo == 3){
adapter.addFragment(new
BookingDetailFragment("assigned"),"0\nASSIGNED");
}else if (fragmentNo == 4){
adapter.addFragment(new PickUpFragment(),"0\nASSIGNED");
}
// -- For TAB 3
adapter.addFragment(new BookingDelivered(),"0\nDELIVERED");
viewPager.setAdapter(adapter);
}
}