Beste Weg, um Tabs in Android zu implementieren?

Ich habe einen Code durchgesehen, der Registerkarten am unteren Rand der App-Seite implementiert. Und es gibt keine veraltete Methode / Klasse im Code, und für mich ist es eine sehr einfache und saubere Möglichkeit, Tabulatoren zu implementieren.

Ich habe jedoch gehört, dass die neue Art der Implementierung von Registerkarten darin besteht, Fragmente zu verwenden.

Also, welches ist besser? Und warum?

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TabHost
        android:id="@+id/edit_item_tab_host"
        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"
            android:layout_gravity="bottom" />


            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:paddingTop="65px" >

            <LinearLayout
                android:id="@+id/edit_item_date_tab"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:padding="5px" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="date"
                    android:textStyle="bold" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/edit_item_geocontext_tab"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:padding="5px" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="lieu"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/edit_item_text_tab"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:padding="5px" >
            </LinearLayout>
        </FrameLayout>
    </TabHost>

</LinearLayout>

MainActivity Klasse:

import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);



        TabHost tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);
        // don't forget this setup before adding tabs from a tabhost using a xml view or you'll get an nullpointer exception
        tab_host.setup(); 

        TabSpec ts1 = tab_host.newTabSpec("TAB_DATE");
        ts1.setIndicator("tab1");
        ts1.setContent(R.id.edit_item_date_tab);
        tab_host.addTab(ts1);

        TabSpec ts2 = tab_host.newTabSpec("TAB_GEO");
        ts2.setIndicator("tab2");
        ts2.setContent(R.id.edit_item_geocontext_tab);
        tab_host.addTab(ts2);

        TabSpec ts3 = tab_host.newTabSpec("TAB_TEXT");
        ts3.setIndicator("tab3");
        ts3.setContent(R.id.edit_item_text_tab);
        tab_host.addTab(ts3);

        tab_host.setCurrentTab(0);




        }
}

Antworten auf die Frage(3)

Ihre Antwort auf die Frage