Frage

Ich versuche zur Zeit des Android 1.5 SDK und ich habe ein paar Beispiele auf TabHost gesehen. Was ich versuche zu tun, einen anderen Knopf auf jedem Tab nutzen, um ihre Aufgaben zu erledigen.

Was ich versucht wurde mit onClickListiner () und onClick (). Ich denke, das ist es, was alle Entwickler verwenden, aber ich halte eine Null-Ausnahme auf dem LogCat die Taste gedrückt wird jedes Mal bekommen. Auch habe ich jedes XML-Layout so nenne ich die Tab als: tab.add (... setContent (R.id.firstTabLayout))

firstTabLayout = layout for Button and TextView.

Was wäre der beste Weg, um eine Schaltfläche / Textview Arbeit ordnungsgemäß unter der TabHost zu machen?

War es hilfreich?

Lösung

Ich bin nicht ganz sicher, wo das Problem ist, aber das ist, wie ich habe meine Tabbed-Aktivitäten einrichten, bevor

layout.xml

<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">

        <TextView android:id="@android:id/text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>
    <LinearLayout android:id="@+id/tab2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TextView android:id="@android:id/text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>
    <LinearLayout android:id="@+id/tab3"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TextView android:id="@android:id/text"
            android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

    </LinearLayout>
</FrameLayout>

Tab.java

public class InitialActivity extends TabActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout);

        TabHost th = getTabHost();
        th.addTab(th.newTabSpec("tab_1").setIndicator("Tab1").setContent(R.id.tab1));
        th.addTab(th.newTabSpec("tab_2").setIndicator("Tab2").setContent(R.id.tab2));
        th.addTab(th.newTabSpec("tab_3").setIndicator("Tab3").setContent(R.id.tab3));
    }
}

Dann können Sie nur findViewById () auf allen Ansichten innerhalb der Registerkarten verwenden, oder wenn es Namen zwischen ihnen geteilt werden, können Sie findViewById(R.id.tab1).findViewById(R.id.text) tun

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top