2012-08-01 6 views
0

I이 탭 레이아웃을 설정이 XML은TabHost 작동하지 않습니다

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

    <LinearLayout 
    android:orientation="vertical" 
    android:id="@+id/myLayout" 
    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"/> 
     <FrameLayout 
     android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp">  
      <!-- tabs are included dynamically from adapter -->   
     </FrameLayout>  
    </LinearLayout> 
</TabHost> 

이 내 활동입니다 :

public class TabBackupRestoreActivity extends SuperActivity { 
    @Override View manageActivity() throws Exception { 
     return new TabBackupRestoreAdapter(this, this,savedInstanceState); 
    } 
} 

이것은 모든 탭을 관리하는 어댑터입니다 :

public class TabBackupRestoreAdapter extends TabHost { 

    private static int TAB_HEIGHT=40; 
    TabHost thisView; 

    public TabBackupRestoreAdapter(Context context,ActivityGroup act,Bundle state) { 
     super(context); 
     thisView = (TabHost)inflate(getContext(), R.layout.tab_backup_restrore, this); 

     LocalActivityManager lam = act.getLocalActivityManager(); 
     lam.dispatchCreate(state); 
     thisView.setup(lam); 

     addNewTab(R.string.backup,new Intent(getContext(),BackupActivity.class)); 
     addNewTab(R.string.restore, new Intent(getContext(),RestoreActivity.class)); 
    } 

    private void addNewTab(int stringId, Intent activity){ 

     TabHost.TabSpec spec = thisView.newTabSpec(getContext().getString(stringId)); 
     spec = spec.setContent(activity); 
     spec = spec.setIndicator(getContext().getString(stringId)); 
     thisView.addTab(spec); 

     //modifico l'altezza del tab 
     int totalTabs = thisView.getTabWidget().getChildCount(); 
     thisView.getTabWidget().getChildAt(totalTabs-1).getLayoutParams().height = TAB_HEIGHT; 
    } 
} 

andorid 2.2가 모두 제대로 작동 할 때까지 Android 4에서이 앱을 실행하면이 예외가 throw됩니다 (

01).
android.content.res.Resources$NotFoundException: Resource ID #0x0 
android.content.res.Resources.getValue(Resources.java:1018) 
android.content.res.Resources.loadXmlResourceParser(Resources.java:2105) 
android.content.res.Resources.getLayout(Resources.java:857) 
android.view.LayoutInflater.inflate(LayoutInflater.java:394) 
android.widget.TabHost$LabelIndicatorStrategy.createIndicatorView(TabHost.java:531) 
android.widget.TabHost.addTab(TabHost.java:223) 
it.hyde.adapters.TabBackupRestoreAdapter.addNewTab(TabBackupRestoreAdapter.java:41) 
it.hyde.adapters.TabBackupRestoreAdapter.<init>(TabBackupRestoreAdapter.java:31) 
it.hyde.activities.TabBackupRestoreActivity.manageActivity(TabBackupRestoreActivity.java:9) 
it.hyde.activities.SuperActivity.onCreate(SuperActivity.java:41) 
android.app.Activity.performCreate(Activity.java:4465) 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
android.app.ActivityThread.access$600(ActivityThread.java:123) 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
android.os.Handler.dispatchMessage(Handler.java:99) 
android.os.Looper.loop(Looper.java:137) 
android.app.ActivityThread.main(ActivityThread.java:4424) 
java.lang.reflect.Method.invokeNative(Native Method) 
java.lang.reflect.Method.invoke(Method.java:511) 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
dalvik.system.NativeStart.main(Native Method) 

android4 라이브러리를 사용하여 컴파일하려고했으나 동일합니다.

이 게시물은 Honeycomb and TabHost specs이며 costructor를 사용하여 해결되었지만 xml을 부풀려 야하므로이 솔루션을 사용할 수 없습니다.

누군가 나를 도와 줄 수 있습니까?

감사


나는이 발견

http://code.google.com/p/android/issues/detail?id=22605

-.- '을

답변

1

그 해결 방법이나 올바른 만약 내가 솔루션, 나도 몰라 발견 방법. 무엇이 변경됩니까? 내가 대신 루트 태그

추적의 XML 코드의 LinearLayout의 자식으로 TabHost을 넣어 :

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

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

     <LinearLayout 
      android:orientation="vertical" 
      android:id="@+id/myLayout" 
      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"/> 
      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:padding="5dp">   
       <!-- tabs are included dynamically from adapter -->   
      </FrameLayout>   
     </LinearLayout> 
    </TabHost>   
</LinearLayout> 

이는 어댑터입니다 :

public class TabBackupRestoreAdapter extends LinearLayout { 

    private static int TAB_HEIGHT=40; 

    TabHost tabView; 

    public TabBackupRestoreAdapter(Context context,ActivityGroup act,Bundle state) { 
     super(context); 
     View view = inflate(getContext(), R.layout.tab_backup_restrore, this); 

     tabView = (TabHost)view.findViewById(R.id.tabContainer);  
     LocalActivityManager lam = act.getLocalActivityManager(); 
     lam.dispatchCreate(state); 
     tabView.setup(lam); 

     addNewTab(R.string.backup,new Intent(getContext(),BackupActivity.class)); 
     addNewTab(R.string.restore, new Intent(getContext(),RestoreActivity.class)); 
    } 

    private void addNewTab(int stringId, Intent activity){ 

     TabHost.TabSpec spec = tabView.newTabSpec(getContext().getString(stringId)); 
     spec = spec.setIndicator(getContext().getString(stringId)); 
     spec = spec.setContent(activity); 
     tabView.addTab(spec); 

     //modifico l'altezza del tab 
     int totalTabs = tabView.getTabWidget().getChildCount(); 
     tabView.getTabWidget().getChildAt(totalTabs-1).getLayoutParams().height = TAB_HEIGHT; 
    } 
}