繁体   English   中英

操作栏向上导航活动到片段

[英]Action Bar UP navigation Activity to Fragment

我正在开发一个带导航抽屉的应用程序。 虽然我之前没有片段经验,但我可以成功实现导航抽屉。 现在我的问题是,我想要一个Action Bar后退按钮。 我之前尝试过这个活动。 但现在问题是我有一个片段里面有一个点击事件。 当用户单击该按钮时,它将转到其中包含列表视图的活动。 现在我想使用操作栏向上按钮返回上一个片段。 我该怎么做? 当我按下手机上的后退按钮时,它正常工作。

我在列表视图活动中实现了onOptionsItemSelected,如下所示。 当我按下操作栏向上按钮时,它会进入登录窗口。 不是我想去的地方。

public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is NOT part of this app's task, so create a new task
            // when navigating up, with a synthesized back stack.
            TaskStackBuilder.create(this)
                    // Add all of this activity's parents to the back stack
                    .addNextIntentWithParentStack(upIntent)
                    // Navigate up to the closest parent
                    .startActivities();
        } else {
            // This activity is part of this app's task, so simply
            // navigate up to the logical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

任何人都可以在这个问题上提供一些帮助吗?

我想在这篇文章中: 在主/细节片段中使用ActionBar Up Navigation,您可以找到答案来解决这个问题。

我认为你必须使用FragmentManager而不是Activity。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM