java - method is not invoked -


method not invoked

//view flipper code  ...................................... public class homeactivity extends appcompatactivity implements navigationview.onnavigationitemselectedlistener { private viewflipper mviewflipper; private float initialx; private context mcontext;    @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_home);      mcontext = this;     mviewflipper = (viewflipper) this.findviewbyid(r.id.view_flipper);      //play , stop button image slideshow(working fine)      findviewbyid(r.id.play).setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             mviewflipper.setautostart(true);             mviewflipper.setflipinterval(1000);             mviewflipper.startflipping();         }     });      findviewbyid(r.id.stop).setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             mviewflipper.stopflipping();          }     });  } //the below method not getting invoked  public boolean ontouchevent(motionevent touchevent) {     switch (touchevent.getaction()) {         case motionevent.action_down:             initialx = touchevent.getx();             system.out.println(initialx);              //not displaying value in android              monitor             break;         case motionevent.action_up:             float finalx = touchevent.getx();             system.out.println(finalx);             //not displaying value in android monitor             if (initialx > finalx) {                 if (mviewflipper.getdisplayedchild() == 0)                  //image flipper has 3 images                     break;                 mviewflipper.shownext();             } else {                 if (mviewflipper.getdisplayedchild() == 2)                     break;                 mviewflipper.showprevious();             }             break;     }     return false; } } 

well, seems you're trying perform action on touching view. should override ontouchlistener of view want receive touch event. can done follows:

findviewbyid(r.id.your_view_id).setontouchlistener(new view.ontouchlistener() {         @override         public boolean ontouch(view v, motionevent event) {             switch (touchevent.getaction()) {                 case motionevent.action_down:                     initialx = touchevent.getx();                     system.out.println(initialx);                     break;                 case motionevent.action_up:                     float finalx = touchevent.getx();                     system.out.println(finalx);                     if (initialx > finalx) {                         if (mviewflipper.getdisplayedchild() == 0)                             //image flipper has 3 images                             break;                         mviewflipper.shownext();                     } else {                         if (mviewflipper.getdisplayedchild() == 2)                             break;                         mviewflipper.showprevious();                     }                     break;             }             return false;         }     }); 

Comments

Popular posts from this blog

javascript - Replicate keyboard event with html button -

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Web audio api 5.1 surround example not working in firefox -