我可以把它尚未初始化上Backstack片段? [英] Can I put a fragment on Backstack which hasn't been initialized yet?
问题描述
我想删除从backstack片段,并把已没有被创建在它的地方的另一个片段。下面是我想要达到的图片。
有没有办法做到这一点?
编辑:
正如@Elltz指出,这是不可能的。所以我的问题就变成了
-
是否有可能从后堆栈摧毁最后一个片段?
-
我能处理手动pssed提供比什么是背堆栈上的不同片段后退按钮$ P $?
NO ! 否! 否!
要从中删除backstack片段,并把另一片段
块引用>您不能手动重新安排
BackstackEntry
。你只能听,观察并调用它。看看PopBackstack(字符串名称,诠释标志)
因此的第一个没有的
和把另一个片段,其中还尚未创建它的地方。
块引用>您的意思是
空
片段
?..你也不能分配给引用空
对象的第二个没有的
有没有办法做到这一点?
块引用>一个确认号
修改
是! 是! 是!
是否有可能破坏从后堆栈中最后一个片段?
块引用>即可;使用 FragmentManager &安培; FragmentTransaction
FragmentManager FM = FragmentActivity.getSupportFragmentManager();
fm.beginTransaction()。删除(
fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1));第一个是
我能处理手动pssed提供比什么是背堆栈上的不同片段后退按钮$ P $?
块引用>是的,你可以,但你必须这样做,在你的
FragmentActivity
或活动
,所以你需要一些接口
或围绕自己的逻辑,或
用自己的逻辑实现BackStackChangedListener
,这其实是接口
我说的用逻辑,这个监听器被随时通知一个片段
进入或离开Backstack
,因此,第二是的三是被呵护。
希望它可以帮助爵士。
I want to remove a fragment from backstack and put another fragment in its place which hasn't been created yet. Below is a picture of what I want to achieve.
Is there any way to accomplish this?
EDIT:
As pointed out by @Elltz, it's not possible. So my question becomes
Is it possible to destroy the last fragment from back stack?
Can I handle the back button pressed manually to provide a different fragment than what is on the back stack?
解决方案NO! NO! NO !
want to remove a fragment from backstack and put another fragment
you can not manually re-arrange the
BackstackEntry
. you can only listen,observe and call it. look intoPopBackstack(String name, int flags)
hence the first noand put another fragment in its place which hasn't been created yet
you mean a
null
Fragment
?.. you can not also assign references tonull
object, the second noIs there any way to accomplish this?
A confirmation No.
EDIT
YES! YES! YES!
Is it possible to destroy the last fragment from back stack?
you can; using FragmentManager & FragmentTransaction
FragmentManager fm = FragmentActivity.getSupportFragmentManager(); fm.beginTransaction().remove( fm.getBackStackEntryAt(fm.getBackStackEntryCount()-1););
the first yes
Can I handle the back button pressed manually to provide a different fragment than what is on the back stack?
Yes, you can, but you have to do it in your
FragmentActivity
orActivity
so you will need someinterface
or your own logic around that, or with your own logic implementingBackStackChangedListener
, this is actually theinterface
i was talking about with logic, this listener gets notified anytime aFragment
goes or leaves theBackstack
, hence the second yesThird yes was for pampering.
Hope it helps Sir.
这篇关于我可以把它尚未初始化上Backstack片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!