1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package com.example.android.supportv4.app; 17 18//BEGIN_INCLUDE(complete) 19import com.example.android.supportv4.R; 20 21import android.os.Bundle; 22import android.support.v4.app.FragmentActivity; 23import android.support.v4.app.FragmentTabHost; 24 25/** 26 * This demonstrates how you can implement switching between the tabs of a 27 * TabHost through fragments, using FragmentTabHost. 28 */ 29public class FragmentTabs extends FragmentActivity { 30 private FragmentTabHost mTabHost; 31 32 @Override 33 protected void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 36 setContentView(R.layout.fragment_tabs); 37 mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost); 38 mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); 39 40 mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"), 41 FragmentStackSupport.CountingFragment.class, null); 42 mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"), 43 LoaderCursorSupport.CursorLoaderListFragment.class, null); 44 mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"), 45 LoaderCustomSupport.AppListFragment.class, null); 46 mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"), 47 LoaderThrottleSupport.ThrottledLoaderListFragment.class, null); 48 } 49} 50//END_INCLUDE(complete) 51