android - How can I make my arrows invisible by setCurrentItem method of Viewpager? -


in oncreate of mainactivity add code:

mdateareaslider.addonpagechangelistener(new viewpager.onpagechangelistener() {             @override             public void onpageselected(int arg0) {                      // hide right arrow if reach last position                      if (arg0 == adapter.datelist.length - 1) {                         mbuttonnext.setvisibility(view.invisible);                         mbuttonback.setvisibility(view.visible);                     }                      // hide left arrow if reach first position                      else if (arg0 == 0) {                         mbuttonback.setvisibility(view.invisible);                         mbuttonnext.setvisibility(view.visible);                     }                      // else show both arrows                     else {                         mbuttonback.setvisibility(view.visible);                         mbuttonnext.setvisibility(view.visible);                     }                 }             }              @override             public void onpagescrolled(int arg0, float arg1, int arg2) {                 // todo auto-generated method stub                 ifsingding = true;             }              @override             public void onpagescrollstatechanged(int arg0) {                 // todo auto-generated method stub             }         }); 

and on button click add code:

mdateareaslider.setcurrentitem(0); 

but problem can slide page selected not make arrows invisible.

note: 2 arrows imageviews in main layout,not inflated layout.so nothing adapter.

replace original code this:

final viewpager.onpagechangelistener onpagechangelistener = new viewpager.onpagechangelistener() {         @override         public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) {          }          @override         public void onpageselected(int position) {             if (position == adapter.datelist.length - 1) {                     mbuttonnext.setvisibility(view.invisible);                     mbuttonback.setvisibility(view.visible);                 }                  // hide left arrow if reach first position                  else if (position == 0) {                     mbuttonback.setvisibility(view.invisible);                     mbuttonnext.setvisibility(view.visible);                 }                  // else show both arrows                 else {                     mbuttonback.setvisibility(view.visible);                     mbuttonnext.setvisibility(view.visible);                 }         }          @override         public void onpagescrollstatechanged(int state) {          } }; mdateareaslider.addonpagechangelistener(onpagechangelistener); 

execute code on button click

mdateareaslider.setcurrentitem(0); mdateareaslider.post(new runnable() {         @override         public void run() {             onpagechangelistener.onpageselected(0);         } }); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -