2014-10-14 3 views
3

Android에서 새로 생겼습니다. 간단한 TabHost보기를 설정하려고합니다. Android - android.widget.TabHost를 android.support.v4.app.FragmentTabHost에 캐스팅 할 수 없습니다.

내 XML 파일입니다

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

그리고 여기 내 자바 코드 :

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); 


    } 
} 

그러나이 오류 메시지와 함께 응용 프로그램 충돌 (정말 뜻 모르겠어요) :

enter image description here

당신은 잘못 될 수에 대해 어떻게 생각하십니까? 대신

답변

5

사용 :

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

(...) 

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

는 너무 감사드립니다. –