android,如何将一个片段带到backstack的顶部,并保持其他片段不变

问题描述

具有一个活动,其中包含一堆碎片。在后面的堆栈中,这些碎片将位于

[FA,FB,FC],并且只有前一个FA在布局中并显示

现在,如果需要显示一个FD,则FD将位于顶部:[FD,FA,FB,FC]。

但是,如果FB不在顶部,并且想再次显示FB,则应将其更改为:[FB,FD,FA,FC],因此将FB从第三位置移至第一位置,并保持其他人的顺序保持不变。

有可能吗?

它正在使用replace来保留未显示的片段。

fun showFragment(tag: String) {
        var frgmt = supportFragmentManager.findFragmentByTag(tag)
        if (frgmt == null) {
            frgmt = createTheFragment(tag)  // get new Fragment by the 'tag'
        } else {
            // how to only remove it from the backStack ???

            // this pops all above
            //val fragmentPopped: Boolean = supportFragmentManager.popBackStackImmediate(tag,0)

            // does it have thing like:
            //supportFragmentManager.removeFromBackStack(tag)

        }

        supportFragmentManager.beginTransaction()
            .addToBackStack(tag)
            .replace(R.id.fragment_container,frgmt)
            .commit()
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)