android - 如何自定义处理for Fragment的BackPressed键?

标签 android android-fragments

在我的 android 应用程序中,我使用了 fragment ,但是在处理返回键时我遇到了问题, 我的结构是,

它的用户账户结构,在那,

1)Main Wall=>在那个子 fragment 中->另一个 fragment ->另一个 fragment

2) 当我单击此屏幕上的一个按钮( friend 墙按钮)时, 然后,打开另一面与主墙相同的墙。

3) 从主墙您将转到另一个下一个屏幕。

当按下后退键时,我已经维护了堆栈 fragment 用于收回。它适用于主墙, 但是对于从 friend 墙到用户墙的返回,它的处理变得困难,

请给我任何处理此类情况的线索或建议。 ,现在我处理 B

最佳答案

这是使用 actionBar 中的向上按钮执行此操作的正确方法,如下面的屏幕截图所示:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

android backstack

关于android - 如何自定义处理for Fragment的BackPressed键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24326706/

相关文章:

android - GetFragmentManager.findFragmentByTag() 返回 null

Android:ViewPager2 在创建时设置起始页不起作用

java - 持久化 fragment 状态

android - 当 iPhone/Android 进入休眠状态时,JavaScript 执行(settimeout 等)会发生什么情况?

android - 读取和写入 XML 文件

android - 从 Activity 创建 fragment 时getView返回null

java - 抽屉导航监听器不在 fragment 中工作

android - 询问用户评价应用程序并提供与 friend 分享应用程序链接的机会的标准方式

android - 将复合对象插入 ContentValues

Android - 带有动画的可扩展 TextView