How to programmatically show next view in ViewPager?

前端 未结 4 1385

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

4条回答
  •  盖世英雄少女心
    2021-02-01 00:46

    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);
    }
    

提交回复
热议问题