如何以编程方式在ViewPager中显示下一个视图?
我创build了一个ViewPager,一切工作正常,但是我想有一个以前的ViewPager之外的下一个button,可以在ViewPager中导航。 我怎样才能去ViewPager的下一个项目,而无需手动刷卡?
由于blessenm回答了viewpager.setCurrentItem(int index)
是要走的路。
一个完整的实现只是为了完整性:
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); }
我更好地解决它,安德森森。
private void MoveNextTopSlideShow(View view) { if (_viewPager_TopImageSlide.CurrentItem == _viewPager_TopImageSlide.ChildCount) { if (_viewPager_TopImageSlide.ChildCount > 0) { _viewPager_TopImageSlide.SetCurrentItem(0,true); } } else { //it doesn't matter if you're already in the last item _viewPager_TopImageSlide.SetCurrentItem(_viewPager_TopImageSlide.CurrentItem + 1, true); } } private void MovePreviousTopSlideShow(View view) { if (_viewPager_TopImageSlide.CurrentItem == 0) { if (_viewPager_TopImageSlide.ChildCount > 0) { _viewPager_TopImageSlide.SetCurrentItem(_viewPager_TopImageSlide.ChildCount-1, true); } } else { //it doesn't matter if you're already in the first item _viewPager_TopImageSlide.SetCurrentItem(_viewPager_TopImageSlide.CurrentItem - 1, true); } }