Android的:如何从tabhost呼叫活动的功能选项卡内 [英] Android: How to call function of Activity inside of tab from the tabhost

查看:105
本文介绍了Android的:如何从tabhost呼叫活动的功能选项卡内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个选项卡一tabhost。每间活动。我想有一个按钮,这是在操作栏,以及常见的顶部按钮栏,调用哪个是活动选项卡的功能。

I have a tabhost with three tabs. Each is an activity. I would like to have a button which is in the action bar, the bar along the top with common buttons, call functions of the tab which is active.

例如,一个附加功能,可以添加不同的东西每个标签取决于什么标签是present当你单击该按钮。

For example, an add function which could add something different to each tab depending on what tab was present when you clicked the button.

所以,我aksing如何从tabHost调用活动A中的函数。

So, I am aksing how to call a function in Activity A from the tabHost.

如果这不会工作,也许我可以更新从tabhost数据库,然后刷新选项卡的内容。请问这是否更容易?

And if that wont work, perhaps I can update the database from the tabhost and then refresh the tab content. Would that be easier?

感谢大家对您的时间和支持。

Thank you all for you time and support.

推荐答案

嗨只是偶然发现了这一点,不知道你是否已经找到了解决办法?

Hi Just stumbled across this, not sure if you already found a solution?

最近,我解决了这个自己。我是previously得到解决该问题通过提高从tabhost活性的意图广播和子选项卡活动中接收广播。这为我工作,但我肯定有一个更好的方式。

I solved this myself recently. I was previously getting around the problem by raising a intent broadcast from the tabhost activity and receiving the broadcast within the sub tab activity. This worked for me but i was sure there is a "better" way.

一个更清洁的方式就是像这样实现的:

A cleaner way is to achieve it with something like this:

可能是这样的:

  • parentActivity - 我的容器 活动持有的TabHost
  • childActivity - 我的选项卡活动 持有标签内容和 公共方法我想从打电话 parentActivity
  • parentActivity - my "container" activity which holds the TabHost
  • childActivity - my tab activity which holds tab content and the public method i want to call from parentActivity

在parentActivity:

within parentActivity:

// a method used for onclick callback or whatever you need. within parentActivity (tabhost)
// this will get call huzzah() in the first tab - getChildAt(0)
onClick () {
  childActivity childAct = (childActivity) getTabHost().getChildAt(0).getContext();
  childAct.huzzah();
}

在childActivity:

within childActivity:

// a public method for the parent activity to access
public void huzzah() {
  Log.d("stuff", "huzzah() called");
}

注:另一种方法我认为是重新设计使用的意见,而不是活动的标签。这是一个更好的整体选择,因为IIRC内存明智的你只存储在堆栈上1活动,而不是( N *标签)的活动数

希望帮助

这篇关于Android的:如何从tabhost呼叫活动的功能选项卡内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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