Tab Fragment Tutorial - Classes - TabDefinition.java


SUBMITTED BY: Guest

DATE: Nov. 18, 2013, 5:30 a.m.

FORMAT: Text only

SIZE: 2.3 kB

HITS: 949

  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. import java.util.UUID;
  18. import android.support.v4.app.Fragment;
  19. import android.view.LayoutInflater;
  20. import android.view.View;
  21. import android.view.ViewGroup;
  22. /**
  23. * A class that defines a UI tab.
  24. */
  25. public abstract class TabDefinition {
  26. //
  27. // Fields
  28. //
  29. private final int _tabContentViewId;
  30. private final String _tabUuid;
  31. //
  32. // Constructors
  33. //
  34. /**
  35. * The constructor for {@link TabDefinition}.
  36. * @param tabContentViewId The layout ID of the contents to use when the tab is active.
  37. */
  38. public TabDefinition(int tabContentViewId) {
  39. _tabContentViewId = tabContentViewId;
  40. _tabUuid = UUID.randomUUID().toString();
  41. }
  42. //
  43. // Exposed Members
  44. //
  45. /**
  46. * Gets the ID of the tab's content {@link View}.
  47. * @return The ID of the tab's content {@link View}.
  48. */
  49. public int getTabContentViewId() {
  50. return _tabContentViewId;
  51. }
  52. /**
  53. * Gets the unique identifier for the tab.
  54. * @return The unique identifier for the tab.
  55. */
  56. public String getId() {
  57. return _tabUuid;
  58. }
  59. /**
  60. * Gets the {@link Fragment} to use for the tab.
  61. * @return The {@link Fragment} to use for the tab.
  62. */
  63. public abstract Fragment getFragment();
  64. /**
  65. * Called when creating the {@link View} for the tab control.
  66. * @param inflater The {@link LayoutInflater} used to create {@link View}s.
  67. * @param tabsView The {@link View} that holds the tab {@link View}s.
  68. * @return The tab {@link View} that will be placed into the tabs {@link ViewGroup}.
  69. */
  70. public abstract View createTabView(LayoutInflater inflater, ViewGroup tabsView);
  71. }

comments powered by Disqus