0

我为一个 android 应用程序创建了一个 tabbedActivity,当我删除一个选项卡并重新添加它时,我收到以下错误

06-28 17:14:22.803: E/AndroidRuntime(18564): FATAL EXCEPTION: main
06-28 17:14:22.803: E/AndroidRuntime(18564): java.lang.IllegalArgumentException: you must specify a way to create the tab indicator.
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.widget.TabHost.addTab(TabHost.java:221)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at com.eema.EvacRouteTableActivity$AsyncMap.onPostExecute(EvacRouteTableActivity.java:248)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at com.eema.EvacRouteTableActivity$AsyncMap.onPostExecute(EvacRouteTableActivity.java:1)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.os.AsyncTask.finish(AsyncTask.java:631)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.os.AsyncTask.access$600(AsyncTask.java:177)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.os.Looper.loop(Looper.java:137)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.app.ActivityThread.main(ActivityThread.java:5041)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at java.lang.reflect.Method.invokeNative(Native Method)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at java.lang.reflect.Method.invoke(Method.java:511)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at dalvik.system.NativeStart.main(Native Method)

这是我的代码:

        @Override
        protected void onPostExecute(Void unused) {

            dialog.dismiss();
            @SuppressWarnings("deprecation")
            TabActivity ta = (TabActivity) EvacRouteTableActivity.this.getParent();
            TabHost tabHost = ta.getTabHost();
            if (MapViewActivity.onCreateCalled >= 2){
                tabHost.getTabWidget().removeView(tabHost.getTabWidget().getChildTabViewAt(4));

                //Tab for the Map
                TabSpec mapSpec = tabHost.newTabSpec("Map");
                Intent mapIntent = new Intent(getBaseContext(), MapViewActivity.class);
                mapSpec.setContent(mapIntent); 
                tabHost.addTab(mapSpec);
                SystemClock.sleep(5000);
            }
            tabHost.setCurrentTab(4);
        }
    }
4

1 回答 1

1

你应该设置一个标签指示器

mapSpec.setIndicator("tab", res.getDrawable(R.drawable.icon));

或者

mapSpec.setIndicator("tab");
于 2013-06-28T23:30:57.320 回答