有没有办法在TabHost显示片段?没有办法、片段、TabHost

2023-09-06 01:15:08 作者:Deception 欺骗

我想显示在TabHost不同的片段,每一个标签。但 似乎,有没有简单的方法来做到这一点。 TabHost只能接受 A.意见或B.意图的发射活动,当用户选择 标签。

I'd like to show a different fragment in a TabHost, for every tab. But it seems that there's no easy way to do this. TabHost can only accept A. Views or B. Intents that launch Activities when the user selects a tab.

要去跟一位意味着我必须初始化每一个片段和负载 他们进入容器视图所给予TabHost。但我想要 这些片段在需要时只加载 - 当用户选择其 标签即是。

Going with A means that I have to initialize every fragment and load them into container Views that are given to the TabHost. But I want these fragments to load only when needed - when the user selects their tab that is.

展望与B表示我加载碎片到单独的活动 每个标签。但我想的片段能够达到的 原来的父母的活动,不只是一些外壳承载活动 他们在一个选项卡的内容。

Going with B means that I load the fragments into separate Activities for each tab. But I'd like the fragment to be able to reach the "original" parent Activity, not just some shell Activity that hosts them in a tab content.

我缺少的东西?有没有办法与管理的碎片 TabHost正确?

Am I missing something? Is there a way to manage fragments with TabHost properly?

推荐答案

下面一些点击:

fragment支持与Tabhost 的Andr​​oid 1.6安培;片段放; Tabhost fragment Support with Tabhost Android 1.6 & Fragment & Tabhost

有关我的理解,链接内TabHost片段是不允许的,你需要创建活动,包括你的片段,然后从TabHost调用这些活动。

For what I understood, "link" a fragment inside a TabHost isn't allowed, you need to create activities that include your fragments and then call these activities from TabHost.

修改 官方的解决方案from谷歌,并与nice动画的。

EDIT the "official solution" from Google, and with nice animations.