我可以把它尚未初始化上Backstack片段? [英] Can I put a fragment on Backstack which hasn't been initialized yet?

查看:236
本文介绍了我可以把它尚未初始化上Backstack片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除从backstack片段,并把已没有被创建在它的地方的另一个片段。下面是我想要达到的图片。

有没有办法做到这一点?

编辑:

正如@Elltz指出,这是不可能的。所以我的问题就变成了


  1. 是否有可能从后堆栈摧毁最后一个片段?


  2. 我能处理手动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

  1. Is it possible to destroy the last fragment from back stack?

  2. 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 into PopBackstack(String name, int flags) hence the first no

and put another fragment in its place which hasn't been created yet

you mean a null Fragment ?.. you can not also assign references to null object, the second no

Is 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 or Activity so you will need some interface or your own logic around that, or with your own logic implementing BackStackChangedListener, this is actually the interface i was talking about with logic, this listener gets notified anytime a Fragment goes or leaves the Backstack, hence the second yes

Third yes was for pampering.

Hope it helps Sir.

这篇关于我可以把它尚未初始化上Backstack片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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