title: Viewpager with auto scroll android
body: <p>I'm using viewpager library to implement image slider but don't know how to implement it to auto scroll. here is my code.</p>
  
  <p><strong>ViewPagerAdapter.java</strong></p>
  
  <pre><code>public class ViewPagerAdapter extends FragmentPagerAdapter implements IconPagerAdapter{
  
  private int[] Images = new int[] { R.drawable.viewpager, R.drawable.viewpager,
          R.drawable.viewpager, R.drawable.viewpager,R.drawable.viewpager, R.drawable.viewpager
  
  };
  
  protected static final int[] ICONS = new int[] { R.drawable.logo,
          R.drawable.logo, R.drawable.logo, R.drawable.logo,R.drawable.logo, R.drawable.logo };
  
  private int mCount = Images.length;
  
  public ViewPagerAdapter(FragmentManager fm) {
      super(fm);
  }
  
  @Override
  public Fragment getItem(int position) {
      return new SliderFragment(Images[position]);
  }
  
  @Override
  public int getCount() {
      // TODO Auto-generated method stub
      return mCount;
  }
  
  public int getIconResId(int index) {
      return ICONS[index % ICONS.length];
  }
  
  public void setCount(int count) {
      if (count &gt; 0 &amp;&amp; count &lt;= 10) {
          mCount = count;
          notifyDataSetChanged();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>SliderFragment.java</strong></p>
  
  <pre><code>public class SliderFragment extends SherlockFragment {
  
  int imageResourceId;
  
  public SliderFragment(int i) {
      imageResourceId = i;
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
  
      ImageView image = new ImageView(getActivity());
      image.setImageResource(imageResourceId);
  
      LinearLayout layout = new LinearLayout(getActivity());
      layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
              LayoutParams.MATCH_PARENT));
  
      layout.setGravity(Gravity.CENTER);
      layout.addView(image);
  
      return layout;
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>mAdapter = new ViewPagerAdapter(getSupportFragmentManager());
      vPager = (ViewPager) findViewById(R.id.pager);
      pIndicator = (PageIndicator) findViewById(R.id.indicator);
      vPager.setAdapter(mAdapter);
      pIndicator.setViewPager(vPager);
      ((CirclePageIndicator) pIndicator).setSnap(true);
  </code></pre>
  
  <p>Please guide me how can i implement it with auto scroll so that images are scrolling automatically after the predefined time.</p>