我有带有查看寻呼机功能的ActionBar选项卡.我的问题是在这些标签中,我无法替换碎片.我使用下面的代码替换片段,但它没有替换,主要片段仍然存在.此外,在其他标签中也存在第二个片段.我的TabListener也低于片段的替换.
private void addFragment(Fragment fragment, boolean addToBackStack, int transition)
{
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.details_container, fragment);
fragmentTransaction.setTransition(transition);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
Run Code Online (Sandbox Code Playgroud)
public static class TabsAdapter extends FragmentPagerAdapter
implements ViewPager.OnPageChangeListener, ActionBar.TabListener {
private final Context mContext;
private final ActionBar mBar;
private final ViewPager mViewPager;
private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
static final class TabInfo {
private final Class<?> clss;
private final Bundle args;
TabInfo(Class<?> _class, Bundle _args) {
clss = _class;
args = _args;
}
}
public TabsAdapter(FragmentActivity activity, ActionBar bar, …Run Code Online (Sandbox Code Playgroud) android android-fragments android-viewpager android-actionbar