2017-03-02 13 views
0

나는이 오류를 얻을 tabhost에 tabhost를 포함하려고Tabhost Tabhost 던지는 런타임 오류 내에서 (귀하의 콘텐츠는 id가 속성 'android.R.id.tabhost'인 TabHost이 있어야합니다)

ava.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tabdemo/com.example.tabdemo.Tab3Activity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 

tab3.java에서 내 tabhost 코드

TabHost tabHost = getTabHost(); 


     // Tab for login 
     TabHost.TabSpec Login = tabHost.newTabSpec("Login2"); 
     // setting Title and Icon for the Tab 

     Login.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.drawtab1)); 
     Intent LoginIntent = new Intent(this, tab1InnerActivity.class); 
     LoginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     Login.setContent(LoginIntent); 

     tabHost.addTab(Login); 

(나는에있을 tabhost 싶어했다)이 내 현재 tab3.xml입니다

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

<LinearLayout 

    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="16dp" 
    android:background="#00547d" 
    > 



    <TextView 
     android:id="@+id/Job_Number_Label" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Job Number" 
     android:textSize="20dp" 
     android:textColor="#ffffff" /> 


</LinearLayout> 
</ScrollView> 

문제는 페이지에 있다고 생각합니다.

답변

1

레이아웃 파일을 변경하고이 레이아웃을 사용하여 요구 사항에 따라 구현하십시오. u는 다음 텍스트보기에 대해 또 다른 사용자 정의 레이아웃을 만들 탭의 텍스트보기와 아이콘을 사용하여 더 자세한 내용은 활동이 레이아웃을 사용할 경우 오류의

원인

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/background"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp"> 

    <LinearLayout 

     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="5dp"> 
     <ScrollView 
      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"> 
      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" /> 
     </ScrollView> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp" /> 




    </LinearLayout> 

</LinearLayout> 
는 텍스트보기입니다 Click here