路过"活动及QUOT;从子标签内容活动于母公司TabActivity [英] Passing "events" from child tab content Activity to parent TabActivity

查看:137
本文介绍了路过"活动及QUOT;从子标签内容活动于母公司TabActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置基本TabActivity非常类似于谷歌的标签教程。然而,上述TabWidget我有我想更新和更改文本后某些事件会在每个子选项卡/子活动发射(不一定标签之间切换时)一个TextView。我意识到我可能无法绑定活动,以便就如何实现这一目标的任何想法之间的事件?安装程序,无论是TabActivity和儿童活动,通过通信的服务?它甚至有可能在这里得到的TextView在TabHost甚至重绘,而子活动是活动的?

I setup a basic TabActivity very similar to Google's tab tutorial. However, above the TabWidget I have a TextView that I'd like to update and change the text after certain events get fired in each child tab/child activity (not necessarily when switching between tabs). I realize I may not be able to bind events between activities so any ideas on how to achieve this? Setup a service that both the TabActivity and children Activities communicate through? Is it even possible to get the TextView here in the TabHost to even redraw while a child activity is active?

我TabActivity膨胀以下几种观点:

My TabActivity inflates the following view:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <TextView android:id="@+id/textToUpdate" android:text="Some text to update" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>

    <TabWidget android:id="@android:id/tabs"
        android:layout_width="fill_parent" android:layout_height="wrap_content" />
    <FrameLayout android:id="@android:id/tabcontent"
        android:layout_width="fill_parent" android:layout_height="fill_parent" />
</LinearLayout>

推荐答案

在做一些很丑陋的解决方法后,终于想出了一个非常简单的解决方案。从孩子的活动中,我说:

After doing some very ugly workarounds, finally figured out a very simple solution. From within the child activity, I added:

protected void updateParentText(){
    MyTabActivity parent = (MyTabActivity) this.getParent();
    TextView tv = (TextView) parent.findViewById(R.id.textToUpdate);
    tv.setText("New Text here");
}

这篇关于路过&QUOT;活动及QUOT;从子标签内容活动于母公司TabActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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