关于父Activity更新UI 这比较麻烦,首先在B和C里面要写入更新UI的方法,然后在A里面开启一个线程监听A的消息事件,tabhost里面每个页面都有个tag,在你开始生成的时候就配置好了,通过那个tag去判断是B还是C去更新,然后用线程调用B和C里面更新UI的方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在 A 页面 Create 的时候就能够获取 b 和 c 的实例, 更新 UI 只是再写个方法调用罢了 看下这段代码应该能懂了吧: TabHost myTabHost; Context c; private ActivityPage_101 activityOne; private ActivityPage_102 activityTwo; private ActivityPage_103 activityThree; private ActivityPage_104 activityFour; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_tabhost); c = this; myTabHost = this.getTabHost(); initTabHost(c,myTabHost, new TabHost.TabSpec[]{ myTabHost.newTabSpec("a").setIndicator(composeLayout("我的任务", R.drawable.tab_weixin_pressed)).setContent(new Intent(c,ActivityPage_101.class)), myTabHost.newTabSpec("b").setIndicator(composeLayout("通讯录", R.drawable.tab_address_pressed)).setContent(new Intent(c,ActivityPage_102.class)), myTabHost.newTabSpec("c").setIndicator(composeLayout("查询", R.drawable.tab_find_frd_pressed)).setContent(new Intent(c,ActivityPage_103.class)), myTabHost.newTabSpec("d").setIndicator(composeLayout("我", R.drawable.tab_settings_pressed)).setContent(new Intent(c,ActivityPage_104.class)) }); initSubActivity(); } public void initTabHost(final Context context, final TabHost tabHost, TabSpec[] tabSpecs) { for (TabSpec tabSpec : tabSpecs) { tabHost.addTab(tabSpec); } final TabWidget tabWidget = tabHost.getTabWidget(); for (int i = 0; i < tabWidget.getChildCount(); i++) { tabWidget.getChildAt(i).getLayoutParams().height = zoom(context,50); } for (int i = tabWidget.getChildCount() - 1; i >= 0; i--) { tabHost.setCurrentTab(i); } } private void initSubActivity() { try { FrameLayout fl = myTabHost.getTabContentView(); for (int i1 = 0; i1 < fl.getChildCount(); i1++) { View v = fl.getChildAt(i1); Object a = v.getContext(); if (a instanceof ActivityPage_101) { activityOne = (ActivityPage_101) a; } if (a instanceof ActivityPage_102) { activityTwo = (ActivityPage_102) a; } if (a instanceof ActivityPage_103) { activityThree = (ActivityPage_103) a; } if (a instanceof ActivityPage_104) { activityFour = (ActivityPage_104) a; } } } catch (Exception ex) { //ActionTool.showException(c, ex); } }<?xml version="1.0" encoding="utf-8"?><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"> <!-- 实现Tab标签的居底主要是通过设置属性 android:layout_weight="1" --> <!-- 还要注意FrameLayout标签的位置,要写在TabWidget标签的前面 --> <FrameLayout android:id="@android:id/tabcontent" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <TabWidget android:id="@android:id/tabs" android:layout_alignParentBottom="true" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout></TabHost> ABC三个没有父子关系,是三个独立的Activity啊, 是这样的,我现在做一个平板项目,一些操作按钮在屏幕顶部是不会动的,下面有几个Activity是会改变的,懂了吗? 是这样的,我现在做一个平板项目,一些操作按钮在屏幕顶部是不会动的,下面有几个Activity是会改变的,懂了吗?哦,刚理解错了,用广播什么的应该可以,更新B还是C这个没什么问题,设置一个标识就好了;如果没有好的解决方法的话可以考虑使用fragment android 怎样彻底删除联系人 请问大家一个问题! 用什么技术做跨电脑和手机的网站最省事? 每次运行弹出launching窗口 PreferenceScreen类如何使某个preference灰掉? 将C函数程序封装成.so动态链接库怎么留接口 android 4.0.3开机时不能收到广播 android 心跳 AIDL 调用的问题 如何在Fragment中获取FragmentActivity中的布局???? 开启热点会发系统广播吗? 自学android,学习那个版本好呢?
TabHost myTabHost;
Context c;
private ActivityPage_101 activityOne;
private ActivityPage_102 activityTwo;
private ActivityPage_103 activityThree;
private ActivityPage_104 activityFour;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_tabhost);
c = this;
myTabHost = this.getTabHost();
initTabHost(c,myTabHost,
new TabHost.TabSpec[]{
myTabHost.newTabSpec("a").setIndicator(composeLayout("我的任务", R.drawable.tab_weixin_pressed)).setContent(new Intent(c,ActivityPage_101.class)),
myTabHost.newTabSpec("b").setIndicator(composeLayout("通讯录", R.drawable.tab_address_pressed)).setContent(new Intent(c,ActivityPage_102.class)),
myTabHost.newTabSpec("c").setIndicator(composeLayout("查询", R.drawable.tab_find_frd_pressed)).setContent(new Intent(c,ActivityPage_103.class)),
myTabHost.newTabSpec("d").setIndicator(composeLayout("我", R.drawable.tab_settings_pressed)).setContent(new Intent(c,ActivityPage_104.class))
});
initSubActivity();
}
public void initTabHost(final Context context,
final TabHost tabHost, TabSpec[] tabSpecs) { for (TabSpec tabSpec : tabSpecs) {
tabHost.addTab(tabSpec);
}
final TabWidget tabWidget = tabHost.getTabWidget();
for (int i = 0; i < tabWidget.getChildCount(); i++) {
tabWidget.getChildAt(i).getLayoutParams().height = zoom(context,50);
}
for (int i = tabWidget.getChildCount() - 1; i >= 0; i--) {
tabHost.setCurrentTab(i);
}
}
private void initSubActivity()
{
try {
FrameLayout fl = myTabHost.getTabContentView();
for (int i1 = 0; i1 < fl.getChildCount(); i1++) {
View v = fl.getChildAt(i1);
Object a = v.getContext();
if (a instanceof ActivityPage_101) {
activityOne = (ActivityPage_101) a;
}
if (a instanceof ActivityPage_102) {
activityTwo = (ActivityPage_102) a;
}
if (a instanceof ActivityPage_103) {
activityThree = (ActivityPage_103) a;
}
if (a instanceof ActivityPage_104) {
activityFour = (ActivityPage_104) a;
}
}
} catch (Exception ex) {
//ActionTool.showException(c, ex);
}
}<?xml version="1.0" encoding="utf-8"?>
<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">
<!-- 实现Tab标签的居底主要是通过设置属性 android:layout_weight="1" -->
<!-- 还要注意FrameLayout标签的位置,要写在TabWidget标签的前面 -->
<FrameLayout android:id="@android:id/tabcontent"
android:layout_weight="1" android:layout_width="fill_parent"
android:layout_height="fill_parent" /> <TabWidget android:id="@android:id/tabs"
android:layout_alignParentBottom="true" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
哦,刚理解错了,用广播什么的应该可以,更新B还是C这个没什么问题,设置一个标识就好了;
如果没有好的解决方法的话可以考虑使用fragment