如何在Fragment类中启动Activity [英] How to start an Activity inside a Fragment class
问题描述
我有两个选项卡,第一个选项卡用于地图,第二个选项卡用于列表. 我试图在第一个标签上显示地图.但是它只显示了布局[return inflater.inflate(R.layout.map_activity,container,false);] 但是除了这个我没有一个活动要映射,我想在不丢失标签的情况下在标签本身内部加载该活动.请帮助我
I have two tabs.First tab is for map .Second tab is for list. And I tried to display the map on the first tab. But it has displayed only the layout [return inflater.inflate(R.layout.map_activity, container, false);] But instead of this I have one activity for map, i want to load that activity without losing tab ,inside the tab itself.Please help me
推荐答案
正如您告诉您要在片段中显示活动一样,您的选项卡是片段.我想说明Fragment
无法托管Activity
.您的Activty
可以有多个片段,但是片段中不能有片段.如果您确实想在选项卡中显示它,则除了将其设置为Fragment
外,别无其他选择.如果您试图在同一选项卡中显示更多内容,而不希望使其显示在整个屏幕上并启动新的Activity
,则可以使用嵌套片段.您可以在同一标签中将一半的屏幕显示为地图,一半则显示为地图.
As you told you want to show activity in fragment, Your tabs are fragments. I want to make clear that Fragment
cant host Activity
. Your Activty
can have multiple fragments, but fragments cannot have fragments inside them. You don't have alternatives than making it Fragment
if you really want to show it in tab. If you are trying to show something more in same tab so that you don't want to make it fill the entire screen and start a new Activity
then there is options of Nested Fragments. You can show half screen as map and half as you want inside same tab.
这篇关于如何在Fragment类中启动Activity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!