从活动中删除片段 [英] Removing fragments from an activity

查看:70
本文介绍了从活动中删除片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FragmantClass rSum = new FragmantClass();
getSupportFragmentManager().beginTransaction().remove(rSum).commit();       

当我加载切换另一个片段时,我正在尝试删除此片段.上面的片段不会被删除.这是我调用的切换片段的方法.

I am trying to remove this fragment, when i load switch another fragment. The above fragment does not get removed. Here is the method i am calling to switch fragments.

public void switchContent(Fragment fragment) {
    FragmantClass rSum = new FragmantClass();
    getSupportFragmentManager().beginTransaction().remove(rSum).commit();
    mContent = fragment;
    getSupportFragmentManager()
        .beginTransaction()
        .replace(R.id.content_frame, fragment)
        .commit();
    getSlidingMenu().showContent();
}

推荐答案

getSupportFragmentManager().beginTransaction().
remove(getSupportFragmentManager().findFragmentById(R.id.frame)).commit();

尝试一下,它应该可以工作.

Try this, it should work.

public void switchContent(Fragment fragment) {
    getSupportFragmentManager().beginTransaction().
    remove(getSupportFragmentManager().findFragmentById(R.id.frame)).commit();
    mContent = fragment;
    getSupportFragmentManager()
        .beginTransaction()
        .replace(R.id.content_frame, fragment)
        .commit();
    getSlidingMenu().showContent();
}

这篇关于从活动中删除片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆