SHARE
TWEET

Tab Fragment Tutorial - Classes - TabDefinition.java

ncosentino Oct 30th, 2013 990 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Blog Post:
  3.  * http://devleader.ca/2013/11/04/fragments-tabbed-android-user-interface
  4.  *
  5.  * Layouts:
  6.  * activity_main.xml: http://pastebin.com/kj8M38Ze
  7.  * fragment_tabs.xml: http://pastebin.com/0b7HAeAK
  8.  * simple_tab.xml: http://pastebin.com/9SqLbS0X
  9.  *
  10.  * Classes:
  11.  * MainActivity.java: http://pastebin.com/eBv3H775
  12.  * SimpleTabDefinition.java: http://pastebin.com/wW3WCcy9
  13.  * TabDefinition.java: http://pastebin.com/KSRV2f3U
  14.  * TabsFragment.java: http://pastebin.com/9Asv7AVH
  15.  */
  16. package com.devleader.tab_fragment_tutorial;
  17.  
  18. import java.util.UUID;
  19.  
  20. import android.support.v4.app.Fragment;
  21. import android.view.LayoutInflater;
  22. import android.view.View;
  23. import android.view.ViewGroup;
  24.  
  25. /**
  26.  * A class that defines a UI tab.  
  27.  */
  28. public abstract class TabDefinition {
  29.         //
  30.         // Fields
  31.         //
  32.         private final int _tabContentViewId;
  33.         private final String _tabUuid;
  34.        
  35.         //
  36.         // Constructors
  37.         //
  38.         /**
  39.          * The constructor for {@link TabDefinition}.
  40.          * @param tabContentViewId The layout ID of the contents to use when the tab is active.
  41.          */
  42.         public TabDefinition(int tabContentViewId) {
  43.                 _tabContentViewId = tabContentViewId;
  44.                 _tabUuid = UUID.randomUUID().toString();
  45.         }
  46.        
  47.         //
  48.         // Exposed Members
  49.         //
  50.         /**
  51.          * Gets the ID of the tab's content {@link View}.
  52.          * @return The ID of the tab's content {@link View}.
  53.          */
  54.         public int getTabContentViewId() {
  55.                 return _tabContentViewId;
  56.         }
  57.        
  58.         /**
  59.          * Gets the unique identifier for the tab.
  60.          * @return The unique identifier for the tab.
  61.          */
  62.         public String getId() {
  63.                 return _tabUuid;
  64.         }
  65.        
  66.         /**
  67.          * Gets the {@link Fragment} to use for the tab.
  68.          * @return The {@link Fragment} to use for the tab.
  69.          */
  70.         public abstract Fragment getFragment();
  71.        
  72.         /**
  73.          * Called when creating the {@link View} for the tab control.
  74.          * @param inflater The {@link LayoutInflater} used to create {@link View}s.
  75.          * @param tabsView The {@link View} that holds the tab {@link View}s.
  76.          * @return The tab {@link View} that will be placed into the tabs {@link ViewGroup}.
  77.          */
  78.         public abstract View createTabView(LayoutInflater inflater, ViewGroup tabsView);
  79. }
RAW Paste Data
Top