2016-07-19 8 views
0

私のナビゲーション・ドロワーの断片にスワイプ・タブ・レイアウトを挿入するための公式Androidチュートリアルに従っています。ナビゲーション・ドロワーの断片の中でスワイプ・タブ・レイアウトを作成するにはどうすればいいですか?

import com.example.android.supportv4. 
    import android.os.Bundle; 
    import android.support.v4.app.FragmentActivity; 
    import android.support.v4.app.FragmentTabHost; 

/** 
* This demonstrates how you can implement switching between the tabs of a 
* TabHost through fragments, using FragmentTabHost. 
*/ 
public class FragmentTabs extends FragmentActivity { 
private FragmentTabHost mTabHost; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.fragment_tabs); 
    mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost); 
    mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); 

    mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"), 
      FragmentStackSupport.CountingFragment.class, null); 
    mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"), 
      LoaderCursorSupport.CursorLoaderListFragment.class, null); 
    mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"), 
      LoaderCustomSupport.AppListFragment.class, null); 
    mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"), 
      LoaderThrottleSupport.ThrottledLoaderListFragment.class, null); 
    } 
} 

私は "R.id.realtabcontent" 何であるかを理解するのに役立ちます。 このフラグメントのXMLレイアウトを作成するにはどうすればよいですか?

+0

です。そのメソッドのコードを投稿し、正確に何が動作しないかを説明します。 – Vucko

+0

うーん..働いているXMLレイアウト? –

答えて

0

R.id.realtabcontentはFragmentTabHostのIDです。下記の方法で「セットアップ」に依存「fragment_tabs.xml」のための簡単な作業XML

<android.support.v4.app.FragmentTabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/realtabcontent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
    <TabWidget 
    android:id="@android:id/tabs" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 
    <FrameLayout 
    android:id="@android:id/tab_content" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    </FrameLayout> 
</LinearLayout></android.support.v4.app.FragmentTabHost> 
関連する問題