我在重新设置标签交换机之间的片段时遇到了一些问题,我需要替换当前系统,它使用beginTransaction()。replace()来开始交换()。隐藏/显示(),但我和当我打电话给这个时,我得到一个空片段,有人可以帮助我做这个工作吗?
这是我的班级:
public class MainScreen extends BaseActivity{
private Fragment fragment;
public MainScreen() {
super(R.string.app_name);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null)
fragment = getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
if (fragment == null)
fragment = new HomeFragment();
setContentView(R.layout.main_screen);
getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
setBehindContentView(R.layout.main_menu_frame);
getSupportFragmentManager().beginTransaction().replace(R.id.main_menu_frame, new MainMenuListFragment()).commit();
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
getSupportFragmentManager().putFragment(outState, "mContent", fragment);
}
@Override
protected void onResume() {
super.onResume();
getSlidingMenu().showContent();
}
public void switchContent(Fragment fragment) {
FragmentManager fm = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();
ft.hide(this.fragment);
this.fragment = fragment;
ft.show(fragment);
ft.commit();
getSlidingMenu().showContent();
//getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
}
public void setActionBarTitle(String title){
getActionBar().setTitle(title);
}
}
现在我正在做
FragmentManager fm = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction ft = fm.beginTransaction();
ft.hide(this.fragment);
this.fragment = fragment;
ft.show(fragment);
ft.commit();
getSlidingMenu().showContent();
取代getSupportFragmentManager()。beginTransaction()。replace(R.id.content_frame,fragment).commit(); 但是当我隐藏
时,这给我留下了一个空片段有人可以帮助我吗? 谢谢!