设置Fragment切换不从新创建

来源:互联网 发布:centos debian 编辑:程序博客网 时间:2024/05/16 16:11
/** * 设置Fragment切换不从新创建 */private Fragment mContent=null;public void switchContent(Fragment from, Fragment to) {    if (mContent != to) {        mContent = to;        FragmentTransaction transaction = manager.beginTransaction();        if (!to.isAdded()) {    // 先判断是否被add过            transaction.hide(from).add(R.id.fragment_goods_room, to).commit(); // 隐藏当前的fragment,add下一个到Activity中        } else {            transaction.hide(from).show(to).commit(); // 隐藏当前的fragment,显示下一个        }    }}
0 0
原创粉丝点击