Je travaille sur une application Android et je souhaite utiliser 4 onglets pour la navigation en utilisant les activités pour chaque onglet. ici j'ajouté le code que j'ai essayéLes activités ne peuvent pas être ajoutées tant que le groupe conteneur n'a pas été créé. Erreur jette à addTab
c'est mon TabHostActivity
public class TabHostActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_host);
context = getApplicationContext();
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
tabHost.setup(mLocalActivityManager);
TabHost.TabSpec tag4= tabHost.newTabSpec(TAB_4_TAG);
TabHost.TabSpec tag3= tabHost.newTabSpec(TAB_3_TAG);
TabHost.TabSpec tag2= tabHost.newTabSpec(TAB_2_TAG);
TabHost.TabSpec tag1= tabHost.newTabSpec(TAB_1_TAG);
tag1.setIndicator("AboutCollege", getResources().getDrawable(R.drawable.college)).setContent(new Intent(this, AboutCollegeActivity.class));
tag2.setIndicator("Focus of Course", getResources().getDrawable(R.drawable.course)).setContent(new Intent(this, AboutCollegeActivity.class));
tag3.setIndicator("Admision", getResources().getDrawable(R.drawable.admission)).setContent(new Intent(this, AboutCollegeActivity.class));
tag4.setIndicator("Contact Details", getResources().getDrawable(R.drawable.contact)).setContent(new Intent(this, AboutCollegeActivity.class));
tabHost.addTab(tag1);
tabHost.addTab(tag2);
tabHost.addTab(tag3);
tabHost.addTab(tag4);
}
}
c'est mon tabHost.xml
<?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="match_parent" android:layout_height="match_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>
</TabHost>
c'est l'erreur journal
15: 41.601 12232-12232/com.after2.svirtzone.after2_gradle E/AndroidRuntime: FATAL EXCEPTION: principal java.lang.RuntimeException: Impossible de démarrer l'activité ComposantInfo {com.after2.svirtzone.after2_gradle/com.after2.svirtzone.after2_gradle.TabHostActivity}: java.lang.IllegalStateException: Les activités ne peuvent être ajoutés jusqu'à ce que le groupe contenant a été créé. à android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2262) à android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2316) à android.app.ActivityThread.access 700 $ (ActivityThread.java:158) à android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1296) à android.os.Handler.dispatchMessage (Handler.java:99) à android.os.Looper.loop (Looper.java: 176) à android.app.ActivityThread.main (ActivityThread.java:5365) à java.lang .reflect.Method.invokeNative (méthode native) à java.lang.reflect.Method.invoke (Method.java:511) à com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1102) à com.android.internal.os.ZygoteInit.main (ZygoteInit.java:869) à dalvik.system.NativeStart.main (méthode native) Causé par: java.lang.IllegalStateException: les activités ne peuvent pas être ajoutées jusqu'à ce que le groupe conteneur ait été créé. à android.app.LocalActivityManager.startActivity (LocalActivityManager.java:262) à android.widget.TabHost $ IntentContentStrategy.getContentView (TabHost.java:820) à android.widget.TabHost.setCurrentTab (TabHost.java: 484) à android.widget.TabHost.addTab (TabHost.java:286) à com.after2.svirtzone.after2_gradle.TabHostActivity.onCreate (TabHostActivity.java:70) à android.app.Activity.performCreate (activité .java: 5326) at android.app.Instrumentation.callActivityOnCreate (Instrumentation.ja va: 1097) à android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2225) à android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2316) à android.app.ActivityThread.access 700 $ (ActivityThread .java: 158) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1296) à android.os.Handler.dispatchMessage (Handler.java:99) à android.os.Looper.loop (Looper.java:176) at android.app.ActivityThread.main (ActivityThread.java:5365) à java.lang.reflect.Method.invokeNative (Méthode native) à java.lang.reflect.Method.invoke (Method.java:511) à com.android.internal.os. ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1102) à com.android.internal.os.ZygoteInit.main (ZygoteInit.java:869) à dalvik.system.NativeStart.main (méthode native)
Lorsque je clique sur le bouton d'une autre activité, il se déplace vers ce tabhost. ici j'ai eu l'exception comme dans le journal des erreurs. J'ai cherché mais malheureusement je n'ai pas le answer.please clair hep moi pour résoudre ce problème