title: onTabSelected change Fragment
body: <p>I am trying to change the Fragment <code>onTabSelected</code>.</p>
  
  <p>Because at the moment, if you swipe the transitions work fine. But if you click on the <code>Tab</code>, the Fragments won't switch. The <code>Tab</code> gets highlighted, but the content remains the same.</p>
  
  <p>The issue is with my <code>onTabSelected</code> method. I need a suggestion on how to switch to Fragments <code>onTabSelected</code>.</p>
  
  <p>Unfortunately I cannot extend my <code>MainActivity</code> to <code>FragmentActivity</code>, since I won't be able to use <code>ActionBar</code> in that case (I am required to extend <code>ActionBarActivity</code>).</p>
  
  <p><strong>onTabSelected snippet:</strong></p>
  
  <pre><code>@Override
  public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
    int position = tab.getPosition();
  
    switch (position) {
      case 0:
          break;
      case 1:
          break;
      case 2:
          break;
    }
  }
  </code></pre>
  
  <p><strong>Part of MainActivity that matters here:</strong></p>
  
  <pre><code>public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {
  
      private ViewPager viewPager;
      private TabsPagerAdapter mAdapter;
      private ActionBar actionBar;
  
      // Tab titles
      private String[] tabs = { "Novice", "Članki", "O Tribuni" };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          // Initilization
          viewPager = (ViewPager) findViewById(R.id.pager);
          actionBar = getSupportActionBar();
          mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
  
          viewPager.setAdapter(mAdapter);
          actionBar.setHomeButtonEnabled(false);
          actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_TABS);
  
          // Adding Tabs
          for (String tab_name : tabs) {
              actionBar.addTab(actionBar.newTab().setText(tab_name)
                      .setTabListener(this));
  
          }
  
          /**
           * on swiping the viewpager make respective tab selected
           * */
          viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  
              @Override
              public void onPageSelected(int position) {
                  // on changing the page
                  // make respected tab selected
                  actionBar.setSelectedNavigationItem(position);
              }
  
              @Override
              public void onPageScrolled(int arg0, float arg1, int arg2) {
              }
  
              @Override
              public void onPageScrollStateChanged(int arg0) {
              }
          });
  
  
      }
  </code></pre>
  
  <p>Any help / suggestion appreciated.</p>