title: View pager With Fragments and Indicator
body: <p>I am developing an app in which I have implemented ViewPager I want the user to swipe  and get the next screen. I am implementing fragments. All is well but I want one more thing. I want to indicate which screen is active now, just like tabs. I searched over the internet but did not find any thing helpful. If there is an idea that would be appriciated.</p>
  <hr />
  <p>Here is my view pager adapter and fragment activity and xml layout</p>
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  import com.viewpagerindicator.TitlePageIndicator;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.view.ViewPager;
  import android.support.v4.view.ViewPager.OnPageChangeListener;
  import android.widget.Toast;
  
  public class MainActivity extends FragmentActivity implements OnPageChangeListener {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          
          List&lt;Fragment&gt; list = new ArrayList&lt;Fragment&gt;();
          list.add(MyFragment.newInstance(&quot;fragment 1&quot;));
          list.add(MyFragment.newInstance(&quot;fragment 2&quot;));
          list.add(MyFragment.newInstance(&quot;fragment 3&quot;));
          MyPagerAdapter a = new MyPagerAdapter(getSupportFragmentManager(), list);
          ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
          pager.setAdapter(a);
          
      }
  
      @Override
      public void onPageScrollStateChanged(int arg0) {
          // TODO Auto-generated method stub
          
      }
  
      @Override
      public void onPageScrolled(int arg0, float arg1, int arg2) {
          // TODO Auto-generated method stub
      }
  
      @Override
      public void onPageSelected(int arg0) {
          // TODO Auto-generated method stub
          
      }
  
  
  }
  </code></pre>
  <p>adapter.java</p>
  <pre><code>package com.example.fragments;
  
  import java.util.List;
  
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.PagerAdapter;
  import android.view.View;
  
  public class MyPagerAdapter extends FragmentPagerAdapter {
      List&lt;Fragment&gt; fragments;
      public MyPagerAdapter(FragmentManager fm,List&lt;Fragment&gt; f) {
          super(fm);
          this.fragments = f;
      }
      
      @Override
      public Fragment getItem(int arg0) {
          
          return fragments.get(arg0);
      }
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return fragments.size();
      }
  }
  </code></pre>
  <p>main.xml</p>
  <pre><code>&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot; &gt;
  
  
      &lt;android.support.v4.view.ViewPager
          android:id=&quot;@+id/viewpager&quot;
          android:layout_below=&quot;@+id/titles&quot;
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;fill_parent&quot; /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>