Android 选项卡 - 开始一个新活动
TabHost 中有 4 个选项卡,分别是 A、B、C 和 D。现在每个选项卡只是一个索引页,单击其中任何一个选项卡都会显示不同的活动。
问题是,当用户从选项卡中显示的内容中选择某些内容时,我需要启动另一个活动。其他活动也应该显示在父选项卡本身中。是否可以?或者我必须尝试别的东西吗?
There are 4 Tabs in a TabHost, let them be A, B, C, and D. Now each one is just an index page and clicking on any of them shows a different activity.
The problem is that I need to start another activity when the user selects something from the content displayed in the tab. The other activity should also be displayed in the parent tab itself. Is it possible? Or will I have to try something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
试试这个,在android Cookbook中找到了这个解决方案,
http://androidcookbook.com/Recipe.seam;jsessionid=5424397F3130CE7769FF 47DD67742911 ?recipeId=1693&recipeFrom=ViewTOC
Try this, found this solution in android cookbook,
http://androidcookbook.com/Recipe.seam;jsessionid=5424397F3130CE7769FF47DD67742911?recipeId=1693&recipeFrom=ViewTOC
您不能更改选项卡的 contentView 而不是启动新的 Activity 吗?
也许我错了,但我认为在选项卡中启动活动是不可能的,因为 TabView 托管在活动中,而不是相反(Tabview 不托管每个选项卡的活动)。
Can't you change the contentView of your tab instead of starting a new Activity ?
Maybe I'm wrong but I think also that starting an activity in a tab isn't possible because the TabView is hosted in a activity and not the opposite (Tabview don't host an activity per Tab).
我认为普遍的共识是,由于这些限制,最好不要使用单个活动作为选项卡内容。请参阅这些问题和答案以获取替代方案的指针:
Android:为什么不应该我在选项卡内使用活动?
Android - 选项卡、MapView、选项卡内的活动
I think the common consensus is that it is best not to use individual Activities as tab content due to these limitations. See these questions and answers for pointers to alternatives:
Android: Why shouldn't I use activities inside tabs?
Android - Tabs, MapView, activities within tabs
总结鲁克马尔·迪亚斯提供的链接。您要做的如下:
复制/粘贴并在当前 Activity 中调用此函数,其中“id”为您要切换到的新 Activity 的布局的“android:id”
这是我如何制作的示例调用以从我当前的选项卡式活动切换视图:
To summarize the link that Rukmal Dias provided. Here's what you do:
Copy/Paste and call this function in your current activity where "id" is the "android:id" for the layout of the new activity you want to switch to
Here's an example of how I make the call to switch views from my current Tabbed Activity:
它失去了视图层次结构。当您按下后退按钮时,就我而言,应用程序将关闭。
It looses the view hierarchy. When you press the back button, in my case, the app closes.