Android Open Source - androidui Tab Layout Activity






From Project

Back to project page androidui.

License

The source code is released under:

MIT License

If you think the Android project androidui listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package course.examples.UI.TabLayout;
/*w  ww.  ja  v  a 2s. c o  m*/
import java.util.ArrayList;
import java.util.Arrays;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;

public class TabLayoutActivity extends Activity {

  private static final String ANIMALS_TABSTRING = "Animals";
  private static final String FLOWERS_TABSTRING = "Flowers";
  protected static final String THUMBNAIL_IDS = "thumbNailIDs";

  // List of Flower thumbnail images
  private ArrayList<Integer> mThumbIdsFlowers = new ArrayList<Integer>(
      Arrays.asList(R.drawable.image1, R.drawable.image2,
          R.drawable.image3, R.drawable.image4, R.drawable.image5,
          R.drawable.image6, R.drawable.image7, R.drawable.image8,
          R.drawable.image9, R.drawable.image10, R.drawable.image11,
          R.drawable.image12));

  // List of Animal thumbnail images
  private ArrayList<Integer> mThumbIdsAnimals = new ArrayList<Integer>(
      Arrays.asList(R.drawable.sample_1, R.drawable.sample_2,
          R.drawable.sample_3, R.drawable.sample_4,
          R.drawable.sample_5, R.drawable.sample_6,
          R.drawable.sample_7, R.drawable.sample_0));

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

    setContentView(R.layout.main);

    // Put ActionBar in Tab Mode
    final ActionBar tabBar = getActionBar();
    tabBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create a GridFragment for the Flower thumbnails
    GridFragment flowerFrag = new GridFragment();

    // Store the list of thumbnails as an argument to the GridFragment
    Bundle args = new Bundle();
    args.putIntegerArrayList(THUMBNAIL_IDS, mThumbIdsFlowers);
    flowerFrag.setArguments(args);

    // Configure a tab for the Flower thumbnail GridFragment
    tabBar.addTab(tabBar.newTab().setText(FLOWERS_TABSTRING)
        .setTabListener(new TabListener(flowerFrag)));

    // Create a GridFragment for the Animal thumbnails
    GridFragment animalFrag = new GridFragment();

    // Store the list of thumbnails as an argument to the GridFragment
    args = new Bundle();
    args.putIntegerArrayList(THUMBNAIL_IDS, mThumbIdsAnimals);
    animalFrag.setArguments(args);

    // Configure a tab for the Animal thumbnail GridFragment
    tabBar.addTab(tabBar.newTab().setText(ANIMALS_TABSTRING)
        .setTabListener(new TabListener(animalFrag)));

  }

  // This class handles user interaction with the tabs
  public static class TabListener implements ActionBar.TabListener {
    private static final String TAG = "TabListener";
    private final Fragment mFragment;

    public TabListener(Fragment fragment) {
      mFragment = fragment;
    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
    }

    // When a tab is selected, change the currently visible Fragment
    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
      Log.i(TAG, "onTabSelected called");

      if (null != mFragment) {
        ft.replace(R.id.fragment_container, mFragment);
      }
    }

    // When a tab is unselected, remove the currently visible Fragment
    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
      Log.i(TAG, "onTabUnselected called");

      if (null != mFragment)
        ft.remove(mFragment);
    }
  }
}




Java Source Code List

com.example.aporter.helloandroidwithimageview.HelloAndroidWithImageViewActivity.java
course.examples.Fragments.DynamicLayout.QuoteViewerActivity.java
course.examples.Fragments.DynamicLayout.QuotesFragment.java
course.examples.Fragments.DynamicLayout.TitlesFragment.java
course.examples.Notification.StatusBarWithCustomView.NotificationSpecialActivity.java
course.examples.Notification.StatusBarWithCustomView.NotificationStatusBarWithExpandedViewActivity.java
course.examples.Notification.Toast.NotificationToastActivity.java
course.examples.Notification.ToastWithCustomView.NotificationToastActivity.java
course.examples.UI.AlertDialog.AlertDialogActivity.java
course.examples.UI.AutoComplete.AutoCompleteActivity.java
course.examples.UI.Button.ButtonActivity.java
course.examples.UI.CheckBox.CheckBoxActivity.java
course.examples.UI.GridView.GridLayoutActivity.java
course.examples.UI.GridView.ImageAdapter.java
course.examples.UI.GridView.ImageViewActivity.java
course.examples.UI.LinearLayout.LinearLayoutActivity.java
course.examples.UI.ListLayout.ListViewActivity.java
course.examples.UI.ListLayout.ListViewAdapter.java
course.examples.UI.MapView.GoogleMapActivity.java
course.examples.UI.RadioGroup.RadioGroupActivity.java
course.examples.UI.RatingsBar.RatingsBarActivity.java
course.examples.UI.RecyclerView.MyRecyclerViewAdapter.java
course.examples.UI.RecyclerView.RecyclerViewActivity.java
course.examples.UI.RelativeLayout.RelativeLayoutActivity.java
course.examples.UI.Spinner.SpinnerActivity.java
course.examples.UI.TabLayout.GridFragment.java
course.examples.UI.TabLayout.ImageAdapter.java
course.examples.UI.TabLayout.ImageViewActivity.java
course.examples.UI.TabLayout.TabLayoutActivity.java
course.examples.UI.TableLayout.TableLayoutActivity.java
course.examples.UI.ViewPager.GalleryWithViewPagerActivity.java
course.examples.UI.ViewPager.ImageAdapter.java
course.examples.UI.ViewPager.ImageHolderFragment.java
course.examples.UI.WebView.WebViewActivity.java
course.examples.UI.datepicker.DatePickerFragmentActivity.java
course.examples.UI.timepicker.TimePickerFragmentActivity.java
course.examples.UI.togglebutton.ToggleButtonActivity.java
course.examples.colorpalettewithnavdrawer.ApplicationTest.java
course.examples.colorpalettewithnavdrawer.DisplayColorActivity.java
course.examples.colorpalettewithnavdrawer.DisplaySingleColorActivity.java
course.examples.colorpalettewithnavdrawer.PaletteNameAdapter.java
course.examples.colorpalettewithswipe.ApplicationTest.java
course.examples.colorpalettewithswipe.DisplayColorPaletteActivity.java
course.examples.colorpalettewithswipe.DisplaySingleColorActivity.java
course.examples.colorpalettewithswipe.PaletteAdapter.java
course.examples.fragments.StaticLayout.QuoteViewerActivity.java
course.examples.fragments.StaticLayout.QuotesFragment.java
course.examples.fragments.StaticLayout.TitlesFragment.java
course.examples.fragments.staticconfiglayout.QuoteViewerActivity.java
course.examples.fragments.staticconfiglayout.QuotesFragment.java
course.examples.fragments.staticconfiglayout.TitlesFragment.java
course.examples.helloandroidwithlogin.ApplicationTest.java
course.examples.helloandroidwithlogin.HelloAndroidWithImageViewActivity.java
course.examples.helloandroidwithlogin.LoginActivity.java
course.examples.modernartpiano.MainActivity.java
course.examples.modernartui.MainActivity.java
course.examples.notification.StatusBar.NotificationStatusBarActivity.java
course.examples.notification.StatusBar.NotificationSubActivity.java
course.examples.quoteviewer.QuoteListActivity.java
course.examples.quoteviewer.TitlesListActivity.java
course.examples.ui.fragmentactionbar.QuoteFragment.java
course.examples.ui.fragmentactionbar.QuoteViewerActivity.java
course.examples.ui.fragmentactionbar.TitlesFragment.java
course.examples.ui.helloworldwithmenus.HelloAndroidWithMenuActivity.java
course.labs.multipane.MainActivity.java
course.labs.multipane.QuoteFragment.java
course.labs.multipane.TitlesFragment.java
course.labs.placebadges.MockLocationProvider.java
course.labs.placebadges.PlaceDownloaderTask.java
course.labs.placebadges.PlaceRecord.java
course.labs.placebadges.PlaceViewActivity.java
course.labs.placebadges.PlaceViewAdapter.java
course.labs.placebadges.PlaceViewDetailActivity.java
course.labs.placebadges_prel.MockLocationProvider.java
course.labs.placebadges_prel.PlaceDownloaderTask.java
course.labs.placebadges_prel.PlaceRecord.java
course.labs.placebadges_prel.PlaceViewActivity.java
course.labs.placebadges_prel.PlaceViewAdapter.java
course.labs.placebadges_prel.PlaceViewDetailActivity.java
examples.course.basiccolorpalette.ApplicationTest.java
examples.course.basiccolorpalette.DisplayColorActivity.java
examples.course.basiccolorpalette.DisplayColorNames.java
examples.course.basiccolorpalette.DisplaySingleColorActivity.java
examples.course.basiccolorpalette.PaletteAdapter.java
examples.course.basiccolorpaletteupnav.ApplicationTest.java
examples.course.basiccolorpaletteupnav.DisplayColorActivity.java
examples.course.basiccolorpaletteupnav.DisplayColorNamesActivity.java
examples.course.basiccolorpaletteupnav.DisplaySingleColorActivity.java
examples.course.basiccolorpaletteupnav.PaletteAdapter.java
examples.course.ticker.TickerDisplayActivity.java
examples.course.uicardview.ApplicationTest.java
examples.course.uicardview.CardViewActivity.java