title: How to set Fragments To Android Tabbed Activity
body: <p>I create new tabbed activity in android and I want to set special fragment for each tabs but I don't know how can I do it!
  I searched on net but nothing found!
  I want to add X_fargment layout to section 2 and make fragment class for each fragment! Can anybody help me?</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {
  
      SectionsPagerAdapter mSectionsPagerAdapter; 
      ViewPager mViewPager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          final ActionBar actionBar = getSupportActionBar();
          actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  
          mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  
          mViewPager = (ViewPager) findViewById(R.id.pager);
          mViewPager.setAdapter(mSectionsPagerAdapter);
          mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
              @Override
              public void onPageSelected(int position) {
                  actionBar.setSelectedNavigationItem(position);
              }
          });
  
          for (int i = 0; i &lt; mSectionsPagerAdapter.getCount(); i++) {
              actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
          }
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.menu_main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {   
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
          // When the given tab is selected, switch to the corresponding page in
          // the ViewPager.
          mViewPager.setCurrentItem(tab.getPosition());
      }
  
      @Override
      public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {}
  
      @Override
      public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {}
  
      public class SectionsPagerAdapter extends FragmentPagerAdapter {
  
          public SectionsPagerAdapter(FragmentManager fm) {
              super(fm);
          }
  
          @Override
          public Fragment getItem(int position) {
              return PlaceholderFragment.newInstance(position + 1);
          }
  
          @Override
          public int getCount() {
              // Show 3 total pages.
              return 3;
          }
  
          @Override
          public CharSequence getPageTitle(int position) {
              Locale l = Locale.getDefault();
              switch (position) {
                  case 0:
                  return getString(R.string.title_section1).toUpperCase(l);
                  case 1:
                  return getString(R.string.title_section2).toUpperCase(l);
                  case 2:
                  return getString(R.string.title_section3).toUpperCase(l);
              }
              return null;
          }
      }
  
      public static class PlaceholderFragment extends Fragment {
  
          private static final String ARG_SECTION_NUMBER = "section_number";
  
          public static PlaceholderFragment newInstance(int sectionNumber) {
          PlaceholderFragment fragment = new PlaceholderFragment();
          Bundle args = new Bundle();
          args.putInt(ARG_SECTION_NUMBER, sectionNumber);
          fragment.setArguments(args);
          return fragment;
          }
  
          public PlaceholderFragment() {}
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
              View rootView = inflater.inflate(R.layout.fragment_main, container, false);
              return rootView;
          }
      }
  }
  </code></pre>