Home | History | Annotate | Download | only in app
      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  */
     16 package com.example.android.supportv4.app;
     17 
     18 //BEGIN_INCLUDE(complete)
     19 
     20 import android.os.Bundle;
     21 
     22 import androidx.fragment.app.FragmentActivity;
     23 import androidx.fragment.app.FragmentTabHost;
     24 
     25 import com.example.android.supportv4.R;
     26 
     27 /**
     28  * This demonstrates how you can implement switching between the tabs of a
     29  * TabHost through fragments, using FragmentTabHost.
     30  */
     31 public class FragmentTabs extends FragmentActivity {
     32     private FragmentTabHost mTabHost;
     33 
     34     @Override
     35     protected void onCreate(Bundle savedInstanceState) {
     36         super.onCreate(savedInstanceState);
     37 
     38         setContentView(R.layout.fragment_tabs);
     39         mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
     40         mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
     41 
     42         mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
     43                 FragmentStackSupport.CountingFragment.class, null);
     44         mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
     45                 LoaderCursorSupport.CursorLoaderListFragment.class, null);
     46         mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
     47                 LoaderCustomSupport.AppListFragment.class, null);
     48         mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
     49                 LoaderThrottleSupport.ThrottledLoaderListFragment.class, null);
     50     }
     51 }
     52 //END_INCLUDE(complete)
     53