Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically show next view in ViewPager?

I created a ViewPager and everything is working fine, however I want to have a previous next button outside of ViewPager which can be used to navigate inside ViewPager. How can I go to next Item on ViewPager without swiping manually?

like image 526
Vaibhav Mishra Avatar asked Oct 18 '11 03:10

Vaibhav Mishra


2 Answers

As blessenm answered viewpager.setCurrentItem(int index) is the way to go.

like image 130
Vaibhav Mishra Avatar answered Sep 20 '22 17:09

Vaibhav Mishra


A complete implementation just for completeness:

public void MoveNext(View view) {     //it doesn't matter if you're already in the last item     pager.setCurrentItem(pager.getCurrentItem() + 1); }  public void MovePrevious(View view) {     //it doesn't matter if you're already in the first item     pager.setCurrentItem(pager.getCurrentItem() - 1); } 
like image 42
Androiderson Avatar answered Sep 18 '22 17:09

Androiderson