Ich arbeite an einer Android-Anwendung mit einer Aktivität, die ein Tab-Layout verwendet. Es gibt zwei Registerkarten, die zwischen den in einigen TextViews angezeigten Inhalten wechseln.Wie wird das gleiche Layout für zwei verschiedene Tabs in einem TabHost angezeigt?
Dies bedeutet, dass die beiden Register-Spezifikationen auf den gleichen Layout zeigen (linear) für Inhalt, R.id.plantilla:
<?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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="@layout/plantilla"/>
</FrameLayout>
</LinearLayout>
Das funktioniert aber nur, wenn ich Sie auf die Registerkarte Schalter 2 und zurück auf 1, dh wenn die Aktivität gestartet wird, kann das Layout "plantilla" nicht mehr gesehen werden, bevor Tabs geändert werden. Das ist mein Problem.
Was ist der einfachste Weg, um dies zu umgehen?
PD: Ich habe versucht, die Linie
<include layout="@layout/plantilla">
im TabHost xml zu duplizieren, aber in diesem Fall kann ich auf nicht an den Textviews Objekten aus dem Java-Code mit findViewById (R.id.someTextView) ;
Danke Freund, aber diese Methode hilft mir nicht, weil ich keine Aktivität nach Tab haben möchte. Ich möchte eine einzelne Aktivität, die TabActivity, die je nach Tab verschiedene Inhalte anzeigt. Der auf den einzelnen Registerkarten angezeigte Inhalt wird von einem privaten Objekt mit der TabActivity gelesen. Wenn ich mehr als eine Aktivität habe, muss ich dieses Objekt unter den Aktivitäten teilen, die meiner Meinung nach komplexer sind als das gleiche Layout für zwei Registerkarten. – cs4r