简体   繁体   English

打开另一个活动的片段

[英]Open a fragment from another activity

I have the following issue. 我有以下问题。 I have an activity with 4 fragments. 我有一个包含4个片段的活动。 One of them contains a list of names, when I click on a name another activity is started using intent ecc. 其中一个包含一个名称列表,当我单击一个名称时,将使用intent ecc启动另一个活动。 This activity displays the personal informations related to the name and contains a button. 此活动显示与姓名相关的个人信息,并包含一个按钮。 The button removes the name from the list using the DELETE request via Http (also personal informations are retrieved using Http, POST). 该按钮使用Http的DELETE请求从列表中删除名称(也使用Http,POST检索个人信息)。

This all works fine, but I would like to know how can I return to the fragment that shows the list of names from this very last activity to view again the list with the names minus the selected one. 一切正常,但是我想知道如何返回显示上一活动名称列表的片段,以再次查看名称减去所选名称的列表。 Suggestions or links where I can get some info are very welcome :) 非常欢迎您获得一些信息的建议或链接:)

To go back to your previous Fragment use: 要返回上一个片段,请使用:

getActivity().getFragmentsManager().popBackStack()

The back stack allows the user to reverse a fragment transaction (navigate backwards). 后退堆栈允许用户撤消片段事务(向后导航)。 Using popBackStack will simulate the back behaviour of the back button. 使用popBackStack将模拟后退按钮的后退行为。 Look at http://developer.android.com/reference/android/app/FragmentManager.html an use the one most suited to your needs. 查看http://developer.android.com/reference/android/app/FragmentManager.html ,这是最适合您需要的一种。

You can simply call 您可以简单地致电

finish()

after the deletions operation of your activity 在删除活动后

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

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