Android - android.widget.TabHost cannot be added to android.support.v4.app.FragmentTabHost

I am new to Android. I am trying to create a simple TabHost view.

This is my xml file:

<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

      <TabHost
            android:id="@+id/tabhost"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <TabWidget
                    android:id="@+id/tabs"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                     android:background="#160203" />

                <FrameLayout
                    android:id="@+id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"/>

            </LinearLayout>

        </TabHost>

</FrameLayout>

      

And here is my Java code:

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;

public class Tabhost extends FragmentActivity {

    private FragmentTabHost tabHost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tabhost);

        tabHost = (FragmentTabHost) findViewById(R.id.tabhost);
        tabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent);

        tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Articulos"),
                ArticulosFragment.class, null);
        tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Tutoriales"),
                TutorialesFragment.class, null);
        tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Cursos"),
                CursosFragment.class, null);


    }
}

      

But the app crashes with this error message (I really don't know what that means):

enter image description here

What do you think might be wrong?

+3


source to share


1 answer


Use instead:



<android.support.v4.app.FragmentTabHost
     android:id="@+id/tabhost"
     android:layout_width="fill_parent"
      android:layout_height="fill_parent">

(...)

</android.support.v4.app.FragmentTabHost>

      

+5


source







All Articles