在Android的一个选项卡中的发射活动 [英] Launching activities within a tab in Android

查看:119
本文介绍了在Android的一个选项卡中的发射活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的交易。我有三个选项卡的应用程序。通过与在选项卡中的项目的各种相互作用我最终推出的其他活动。客户审查这一点,并希望推出的中选项卡上的活动,使标签保持可见,如果用户点击该标签中,可以追溯到在setContent函数中定义的原始活动。这是可能的,我将如何去了解这个从其他的活动? (即子活动,而不是一个限定TabHost并能够访问使用setContent)?

Here's the deal. I have an application with three tabs. Through various interactions with the items in the tabs I end up launching other activities. The client has reviewed this and would like the activities launched "within" the tabs, so the tabs remain visible and if the user clicks the tab it goes back to the original activity defined in the setContent function. Is this possible and how would I go about this from other activities? (ie the child activities, not the one that defines the TabHost and has access to call setContent)?

推荐答案

是可能的标签内开展活动。因此设置则tabspec内容到的ActivityGroup而不是常规的活动。

It is possible to launch activities within tabs. Therefore set the tabspec content to an ActivityGroup instead of a regular Activity.

tabHost.addTab(tabHost.newTabSpec("Tab")
                .setIndicator("Tab")
                .setContent(new Intent(this, YourActivityGROUP.class)
                 .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

从该的ActivityGroup之内你就可以启动另一个活动是这样,只有更新你的选项卡的内容查看。

From within that ActivityGroup you can then start another Activity like this that only updates the contentview of the tab you're in.

class YourActivityGROUP extends ActivityGroup{

@Override
protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      //you van get the local activitymanager to start the new activity

      View view = getLocalActivityManager()
                                .startActivity("ReferenceName", new
      Intent(this,YourActivity.class)
                                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                                .getDecorView();
       this.setContentView(view);

   }
}

这篇关于在Android的一个选项卡中的发射活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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