java - Viewpager setCurrentItem() doesn't update onPageSelected() -
when swipe between questions, loads current page number correctly
but when use next button, first click doesnt loads pagenumber ( mean onpageselected()
doesnt work.) second , other clicks loads content loads 1 page previous.
@override protected void oncreate(final bundle savedinstancestate) { super.oncreate(savedinstancestate); this.setcontentview(r.layout.activity_main); mpager = (viewpager)findviewbyid(r.id.pager); questionpageradapter madapter = new questionpageradapter(); mpager.setadapter(madapter); onpagechangelistener pagechangelistener = new onpagechangelistener() { @override public void onpagescrollstatechanged(int arg0) { } @override public void onpagescrolled(int arg0, float arg1, int arg2) { } @override public void onpageselected(int position) { tv.settext( mpager.getcurrentitem()+""); } }; mpager.setonpagechangelistener(pagechangelistener); question.next.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { mpager.setcurrentitem(getitem(+1)); } } private int getitem(int i) { int = mpager.getcurrentitem(); += a; return i; } });
why not doing in listener:
mpager.setcurrentitem(mpager.getcurrentitem() + 1);
Comments
Post a Comment