在 Android 中的选项卡内启动活动 [英] Launching activities within a tab in Android

查看:26
本文介绍了在 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)));

从该活动组中,您可以启动另一个这样的活动,该活动仅更新您所在选项卡的内容视图.

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天全站免登陆