简体   繁体   English

访问片段的父活动

[英]Access to the parent activity of a fragment

I have an activity that extends SherlockFragmentActivity. 我有一个扩展SherlockFragmentActivity的活动。 Clicking on any button in this activity makes that frame replaced with a fragment. 单击此活动中的任何按钮将使该帧替换为片段。 Fragment contains a ViewPager that a ListView is in it. 片段包含一个ViewPager,其中包含ListView。 OnListItemClick event is located within the fragment. OnListItemClick事件位于片段内。 when clicking on any of the items in the ListView it makes the new fragment open, and this continues to be hierarchical. 单击ListView中的任何项目时,它都会打开新片段,并且该片段仍是分层的。 To open the second and third fragment and etc, Activity does not have control to replace New Fragment. 要打开第二个和第三个片段等,Activity无法控制替换“ New Fragment”。

My question is: 我的问题是:

How can I when I'm in a Fragment, come back to parent activity of this fragment? 当我处于片段中时,如何返回该片段的父级活动?

Thanks 谢谢

Have you ever gone through the official documentation for using Fragments in Android ? 您是否曾经浏览过有关在Android中使用Fragments的官方文档?

Please go through it atleast thrice I'd say cause it is the best place to start learning about fragments. 请说至少三遍,因为这是开始学习片段的最佳位置。 In case you still don't want to do that, here's a sample project (which is also provided by the same site) to start with. 如果您仍然不想这样做,那么这里是一个示例项目 (也由同一站点提供)。

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

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