public void switchContent(Fragment to) {
if (fragment != to) {
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
if (!to.isAdded()) { // 先判断是否被add过
transaction.hide(fragment).add(R.id.content_frame, to).commit(); // 隐藏当前的fragment,add下一个到Activity中
} else {
transaction.hide(fragment).show(to).commit(); // 隐藏当前的fragment,显示下一个
}
this.fragment = (SuperFragment) to;
}
// getSupportFragmentManager().beginTransaction()
// .replace(R.id.content_frame, fragment).commit();
showContent();
}

posted on 2013-10-22 15:54  生之狼  阅读(586)  评论(0编辑  收藏  举报