有没有办法在TabHost显示片段? [英] Is there a way to display fragments in TabHost?

查看:122
本文介绍了有没有办法在TabHost显示片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示在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?

推荐答案

下面一些点击:

  1. <一个href="http://groups.google.com/group/android-developers/browse_thread/thread/ea3b64b8b4ac8ab1">fragment支持与Tabhost
  2. 的Andr​​oid 1.6安培;片段放; Tabhost
  1. fragment Support with Tabhost
  2. 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.

修改 官方的解决方案<一href="http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html">from谷歌,并与<一个href="http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabsPager.html">nice动画的。

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

这篇关于有没有办法在TabHost显示片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆