片段后退按钮 [英] Fragment Back button

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

问题描述

我知道如何将片段添加到backstack,但我怎么知道,当用户presses后退按钮,我离开了这片段和我去?我需要做一定的作用取决于此,所以我需要知道和哪些片段我走了。具体来说,我需要知道我离开让该片段,如果它是一个特定的片段,我可以删除按钮。

I know how to add a Fragment to the backstack but how do I know, when the user presses the back Button, which fragment I left and which I went to? I need to do a certain action depending on this so I need to know from and to which fragment I am going. Specifically I need to know which fragment I left so if it is a certain fragment, I can remove a button.

推荐答案

覆盖 onBack pressed 活动

@Override
public void onBackPressed(){
      FragmentManager fm = getSupportFragmentManager();
      Fragment f = fm.findFragmentById(R.id.content_frame); // get the fragment that is currently loaded in placeholder
      Object tag = f.getTag();
      // do handling with help of tag here
      // call super method
      super.onBackPressed();
}

这篇关于片段后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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