Android ViewPager setCurrentItem not loading the requested page -
i trying move specified page in viewpager.
my code -
if(isfirstcall) { mpageradapter = new screenslidepageradapter(getfragmentmanager(), pageid); mpager.setadapter(mpageradapter); } new handler().post(new runnable() { @override public void run() { mpager.setcurrentitem(currentpageposition); } }); mpager.addonpagechangelistener(new viewpager.simpleonpagechangelistener() { private static final float thresholdoffset = 0.5f; @override public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) { super.onpagescrolled(position, positionoffset, positionoffsetpixels); if (checkdirection) { mpager.setpagingenabled(false); if (thresholdoffset > positionoffset) { checkdirection = false; // call service next page position } else { checkdirection = false; // call service prev page position } } } @override public void onpagescrollstatechanged(int state) { super.onpagescrollstatechanged(state); if ((scrollstarted == false) && (state == viewpager.scroll_state_dragging) ) { scrollstarted = true; checkdirection = true; } else { scrollstarted = false; } } @override public void onpageselected(int position) { } });
when try update currentpageposition variable, viewpager hangs , not move specified page immediately. (it observed that, after approximately 10-15 mins specified page called.)
whereas, if don't modify value of currentpageposition variable, works fine (but moves different page wrong value).
i unable understand going wrong.
please help..
observation -
my observation - onpagescrollstatechanged method not called state = 1. resulting in failure of condition in onpagescrolled. next page not called. don't have idea why onpagescrollstatechanged not getting called state 'scroll_state_dragging'.
change
new handler().post(new runnable() { @override public void run() { mpager.setcurrentitem(currentpageposition); } });
into
mpager.setcurrentitem(currentpageposition); mpageradapter.notifydatasetchanged();
you should run ui change related code main ui thread.
Comments
Post a Comment