我正在尝试通过活动组将活动加载到选项卡中,但活动未加载,最终导致illegalStateException错误:
以下是日志信息的副本:
01-10 11:01:06.201: INFO/WeatherClockWidgetProvider(582): updateTime
01-10 11:01:06.201: INFO/WeatherClockWidgetProvider(582): setCalendarInstance
01-10 11:01:06.211: INFO/WeatherClockWidgetProvider(582): onTimeChanged
01-10 11:01:06.211: INFO/WeatherClockWidgetProvider(582): mHour01HandIndex = 1
01-10 11:01:06.211: INFO/WeatherClockWidgetProvider(582): mHour01HandIndex = 1
01-10 11:01:06.211: INFO/WeatherClockWidgetProvider(582): mHour01HandIndex = 0
01-10 11:01:06.211: INFO/WeatherClockWidgetProvider(582): mHour01HandIndex = 1
01-10 11:01:06.211: INFO/WeatherClockWidgetProvider(582): updateTime id = 3
01-10 11:01:06.211: INFO/WeatherClockWidgetProvider(582): updateCurrentTemperature
01-10 11:01:06.221: INFO/WeatherClockWidgetProvider(582): changeFtoC
01-10 11:01:06.251: INFO/WeatherClockWidgetProvider(582): updateCurrentLocal
01-10 11:01:06.281: INFO/WeatherClockWidgetProvider(582): updateTemperatures
01-10 11:01:06.281: INFO/WeatherClockWidgetProvider(582): setCalendarInstance
01-10 11:01:06.291: INFO/WeatherClockWidgetProvider(582): highT = 48
01-10 11:01:06.291: INFO/WeatherClockWidgetProvider(582): lowT = 43
01-10 11:01:06.291: INFO/WeatherClockWidgetProvider(582): changeFtoC
01-10 11:01:06.301: INFO/System.out(8418): waiting for debugger to settle...
01-10 11:01:06.301: INFO/WeatherClockWidgetProvider(582): changeFtoC
01-10 11:01:06.311: INFO/WeatherClockWidgetProvider(582): updateDate
01-10 11:01:06.311: INFO/WeatherClockWidgetProvider(582): setCalendarInstance
01-10 11:01:06.311: INFO/WeatherClockWidgetProvider(582): updateWeatherDescription
01-10 11:01:06.321: INFO/WeatherClockWidgetProvider(582): updateUpdatedTime
01-10 11:01:06.321: INFO/WeatherClockWidgetProvider(582): setCalendarInstance
01-10 11:01:06.341: ERROR/updateUpdatedTime dateString(582): 1/10/2012
01-10 11:01:06.371: ERROR/updatedTime before(582): Update: JAN.10 9:10 AM
01-10 11:01:06.371: ERROR/updatedTime end(582): Update: JAN.10 9:10 AM
01-10 11:01:06.441: INFO/WeatherClockWidgetProvider(582): bindViews
01-10 11:01:06.441: INFO/WeatherClockWidgetProvider(582): appWidgetId = 3
01-10 11:01:06.501: INFO/System.out(8418): waiting for debugger to settle...
01-10 11:01:06.701: INFO/System.out(8418): waiting for debugger to settle...
01-10 11:01:06.909: INFO/System.out(8418): waiting for debugger to settle...
01-10 11:01:07.110: INFO/System.out(8418): waiting for debugger to settle...
01-10 11:01:07.311: INFO/System.out(8418): debugger has settled (1316)
01-10 11:01:07.501: ERROR/gralloc(126): [unregister] handle 0x6335d0 still locked (state=40000001)
01-10 11:01:08.931: INFO/ActivityManager(126): Displayed activity com.PecAppsRadio/.tabs: 4886 ms (total 4886 ms)
01-10 11:02:00.091: INFO/WeatherClockWidgetProvider(582): updateAllElements
01-10 11:02:00.091: INFO/WeatherClockWidgetProvider(582): updateTime
01-10 11:02:00.091: INFO/WeatherClockWidgetProvider(582): setCalendarInstance
01-10 11:02:00.091: INFO/WeatherClockWidgetProvider(582): onTimeChanged
01-10 11:02:00.091: INFO/WeatherClockWidgetProvider(582): mHour01HandIndex = 1
01-10 11:02:00.091: INFO/WeatherClockWidgetProvider(582): mHour01HandIndex = 1
01-10 11:02:00.091: INFO/WeatherClockWidgetProvider(582): mHour01HandIndex = 0
01-10 11:02:00.091: INFO/WeatherClockWidgetProvider(582): mHour01HandIndex = 2
01-10 11:02:00.091: INFO/WeatherClockWidgetProvider(582): updateTime id = 3
01-10 11:02:00.091: INFO/WeatherClockWidgetProvider(582): updateCurrentTemperature
01-10 11:02:00.091: INFO/WeatherClockWidgetProvider(582): changeFtoC
01-10 11:02:00.111: INFO/WeatherClockWidgetProvider(582): updateCurrentLocal
01-10 11:02:00.111: INFO/WeatherClockWidgetProvider(582): updateTemperatures
01-10 11:02:00.121: INFO/WeatherClockWidgetProvider(582): setCalendarInstance
01-10 11:02:00.131: INFO/WeatherClockWidgetProvider(582): highT = 48
01-10 11:02:00.131: INFO/WeatherClockWidgetProvider(582): lowT = 43
01-10 11:02:00.131: INFO/WeatherClockWidgetProvider(582): changeFtoC
01-10 11:02:00.141: INFO/WeatherClockWidgetProvider(582): changeFtoC
01-10 11:02:00.151: INFO/WeatherClockWidgetProvider(582): updateDate
01-10 11:02:00.151: INFO/WeatherClockWidgetProvider(582): setCalendarInstance
01-10 11:02:00.161: INFO/WeatherClockWidgetProvider(582): updateWeatherDescription
01-10 11:02:00.161: INFO/WeatherClockWidgetProvider(582): updateUpdatedTime
01-10 11:02:00.161: INFO/WeatherClockWidgetProvider(582): setCalendarInstance
01-10 11:02:00.171: ERROR/updateUpdatedTime dateString(582): 1/10/2012
01-10 11:02:00.171: ERROR/updatedTime before(582): Update: JAN.10 9:10 AM
01-10 11:02:00.171: ERROR/updatedTime end(582): Update: JAN.10 9:10 AM
01-10 11:02:00.201: INFO/WeatherClockWidgetProvider(582): bindViews
01-10 11:02:00.201: INFO/WeatherClockWidgetProvider(582): appWidgetId = 3
java代码,它读取包含tabhost和tabwidget控件的xml文件:
public class tabs extends Activity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabmain);
TabHost tabs=(TabHost)findViewById(R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("tag1");
spec.setContent(R.id.tab1);
spec.setIndicator("tab1");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("tab2");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag3");
spec.setIndicator("Favourites", getResources().getDrawable(R.drawable.favourites_star));
spec.setContent(new Intent(this,RadioAppActivityGroup.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
tabs.addTab(spec);
}
private class RadioAppActivityGroup extends ActivityGroup{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = getLocalActivityManager().startActivity("radiotabs", new
Intent(this, favourites.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
this.setContentView(view);
}
}
}
包含tabhost和布局控件的xml代码:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+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">
<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
android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"/>
</FrameLayout>
</LinearLayout>
</TabHost>
答案 0 :(得分:0)
首先阅读this official document of Tab Layout,之后改进您的代码
答案 1 :(得分:0)
而不是调用 tabs.setup();
在该地方尝试以下行
LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
mLocalActivityManager.dispatchCreate(savedInstanceState);
tabs.setup(mLocalActivityManager);
另外,尝试单独创建 RadioAppActivityGroup扩展ActivityGroup 类,而不是将其作为私有内部类,并在manifest aslo中定义它。