title: Difference between these 2 swiping tabs implementations?
body: <p>I have a working code for having 3 tabs, with 3 fragments that you can either horizontally swipe between to change, or you can click on the tab to go to the requested fragment.
  However, I wanted to do some tweaks to my design, and I went over to the Android Developer's website: <a href="https://developer.android.com/training/implementing-navigation/lateral" rel="nofollow noreferrer">Creating swipe views with tabs
  </a>, and it looks completely different than mine. Now I wonder if I should use the code in the developer's website, or keep my own.</p>
  
  <p>Right now I am using ViewPager + TabLayout.</p>
  
  <p>So simple, yet working.
  This also makes me wonder, how come this simple code works, but in the official documentation there's a long story. It just makes me think that if I keep my code in the current design, I might encounter some big problems in the future. 
  Or - if it works - then it works?</p>
  
  <p>MainActivity.java:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          // Find the view pager that will allow the user to swipe between fragments
          ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
  
          // Create an adapter that knows which fragment should be shown on each page
          TabsAdapter adapter = new TabsAdapter(this, getSupportFragmentManager());
  
          // Set the adapter onto the view pager
          viewPager.setAdapter(adapter);
  
          // Find the tab layout that shows the tabs
          TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
  
          // Connect the tab layout with the view pager. This will
          //   1. Update the tab layout when the view pager is swiped
          //   2. Update the view pager when a tab is selected
          //   3. Set the tab layout's tab names with the view pager's adapter's titles
          //      by calling onPageTitle()
          tabLayout.setupWithViewPager(viewPager);
  
      }
  }
  </code></pre>
  
  <p>TabsAdapter.java:</p>
  
  <pre><code>public class TabsAdapter extends FragmentPagerAdapter {
  
      /** Context of the app */
      private Context mContext;
  
  
      public TabsAdapter(Context context, FragmentManager fm) {
          super(fm);
          mContext = context;
      }
  
      /**
       * Return the {@link Fragment} that should be displayed for the given page number.
       */
      @Override
      public Fragment getItem(int position) {
          if (position == 0) {
              return new NbFragment();
          } else if (position == 1) {
              return new LksFragment();
          } else {
              return new ChtFragment();
          }
      }
  
      /**
       * Return the total number of pages.
       */
      @Override
      public int getCount() {
          return 3;
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          if (position == 0) {
              return mContext.getString(R.string.category_nb);
          } else if (position == 1) {
              return mContext.getString(R.string.category_lks);
          } else {
              return mContext.getString(R.string.category_cht);
          }
      }
  </code></pre>
  
  <p>activity_main.xml:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/primary_color"
      android:orientation="vertical"
      tools:context="com.example.barebones.barebones.MainActivity"&gt;
  
      &lt;android.support.design.widget.TabLayout
          android:id="@+id/tabs"
          style="@style/CategoryTab"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" /&gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/viewpager"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And you can see it is completely different than the one on their website. How could it be? I would love to get some clarification, because as a beginner, I feel lost in this sea of information. Which method should I use in order to have swiping tabs that represent different fragments?</p>