Tabhost在另一个标签主机内

时间:2013-02-19 04:26:48

标签: android android-tabhost android-style-tabhost

我的活动中有一个tabhost。有5个选项卡,其中一个选项卡包含另一个tabHost。我需要在tabHost下显示我的第二个tabHost。

即,我的t​​abactivity有5个tabs.and在我的第3个标签中包含另一个TabHost。

让我知道这一点。这就是我初始化tabhosts的方式。

TabHost mytab;
mytab = (TabHost)findViewById(android.R.id.tabhost);

logcat

中显示的错误
02-19 10:46:29.207: E/AndroidRuntime(814): FATAL EXCEPTION: main

02-19 10:46:29.207:E / AndroidRuntime(814):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.netmdapp1 / com.example.netmdapp1.PatientSubTabActivity}:java.lang。 RuntimeException:无法启动活动ComponentInfo {com.example.netmdapp1 / com.example.netmdapp1.Appointment}:java.lang.NullPointerException 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.ActivityThread.startActivityNow(ActivityThread.java:1487) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339) 02-19 10:46:29.207:E / AndroidRuntime(814):at com.example.netmdapp1.PatientGroupActivity.startChildActivity(PatientGroupActivity.java:48) 02-19 10:46:29.207:E / AndroidRuntime(814):at com.example.netmdapp1.PatientsCustomView $ 3.onClick(PatientsCustomView.java:112) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.view.View.performClick(View.java:2485) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.view.View $ PerformClick.run(View.java:9080) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.os.Handler.handleCallback(Handler.java:587) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.os.Handler.dispatchMessage(Handler.java:92) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.os.Looper.loop(Looper.java:123) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.ActivityThread.main(ActivityThread.java:3683) 02-19 10:46:29.207:E / AndroidRuntime(814):at java.lang.reflect.Method.invokeNative(Native Method) 02-19 10:46:29.207:E / AndroidRuntime(814):at java.lang.reflect.Method.invoke(Method.java:507) 02-19 10:46:29.207:E / AndroidRuntime(814):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839) 02-19 10:46:29.207:E / AndroidRuntime(814):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 02-19 10:46:29.207:E / AndroidRuntime(814):at dalvik.system.NativeStart.main(Native Method) 02-19 10:46:29.207:E / AndroidRuntime(814):引起:java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.netmdapp1 / com.example.netmdapp1.Appointment}:java.lang。空指针异常 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.ActivityThread.startActivityNow(ActivityThread.java:1487) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.widget.TabHost $ IntentContentStrategy.getContentView(TabHost.java:654) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.widget.TabHost.setCurrentTab(TabHost.java:326) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.widget.TabHost.addTab(TabHost.java:216) 02-19 10:46:29.207:E / AndroidRuntime(814):at com.example.netmdapp1.PatientSubTabActivity.setupTab(PatientSubTabActivity.java:57) 02-19 10:46:29.207:E / AndroidRuntime(814):at com.example.netmdapp1.PatientSubTabActivity.onCreate(PatientSubTabActivity.java:30) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 02-19 10:46:29.207:E / AndroidRuntime(814):......还有16个 02-19 10:46:29.207:E / AndroidRuntime(814):引起:java.lang.NullPointerException 02-19 10:46:29.207:E / AndroidRuntime(814):at com.example.netmdapp1.Appointment.onCreate(Appointment.java:88) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 02-19 10:46:29.207:E / AndroidRuntime(814):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 02-19 10:46:29.207:E / AndroidRuntime(814):... 26更多

1 个答案:

答案 0 :(得分:0)

tabHost.setCurrentTab(0);属性决定默认选项卡。因此,如果您撰写tabHost.setCurrentTab(n);,则第n个标签将成为默认标签。