ViewPager programmatically scrolling

android, android-viewpager

Solution

Take a look at `ViewPager.setCurrentItem(int)` and combine it with a `TimerTask` or a `Handler`.

Example:

final ViewPager viewPager = ...;
final Handler h = new Handler(Looper.getMainLooper());
final Runnable r = new Runnable() { 
    public void run() {
        viewPager.setCurrentItem(0, true);
        h.postDelayed(r, 5000); 
    }
};
h.postDelayed(r, 5000); 

Be sure to cancel the runnable when appropriate.

Problem

I have a simple `ViewPager`. Is there any possibilities programmatically scroll it every five seconds with usual animation?

Original source