android - Make ontouchListener work when two buttons are pressed -


i have 2 buttons,btn1 , btn2. want play animation while 2 buttons kept in pressed state , animation stopped when either 1 of button gets unpressed or both of them action_up state (unpressed).

here code:

    final animation animation = animationutils.loadanimation(this,             r.anim.aim);      animation.reset();     final imageview maxname = (imageview) findviewbyid(r.id.imageview1);      button btn1 = (button)findviewbyid(r.id.button3);     button btn2 = (button)findviewbyid(r.id.button2);      btn1.setontouchlistener(new ontouchlistener() {          @override         public boolean ontouch(view v, motionevent event) {             int action = event.getactionmasked();               if (action == motionevent.action_down) {                    maxname.startanimation(animation);                } else if (action == motionevent.action_up                     || action == motionevent.action_cancel) {                    maxname.clearanimation();               }             // todo auto-generated method stub             return false;         }    

right playing 1 button, want make changes according wrote above. thankyou. waiting help.

final boolean oneispressed = false;         final boolean twoispressed = false;         final boolean isanimating = false;         button btn1 = (button) findviewbyid(r.id.button3);         button btn2 = (button) findviewbyid(r.id.button2);          view.ontouchlistener touchlistener = new view.ontouchlistener() {              @override             public boolean ontouch(view v, motionevent event) {                 int action = event.getactionmasked();                   if (action == motionevent.action_down) {                     if (v.getid() == r.id.button3) {                         oneispressed = true;                     } else if (v.getid() == r.id.button2) {                         twoispressed = true;                     }                      if (oneispressed && twoispressed && !isanimating) {                         isanimating = true;                         maxname.startanimation(animation);                     }                 } else if (action == motionevent.action_up                         || action == motionevent.action_cancel) {                     isanimating = false;                     maxname.clearanimation();                 }                 return false;             }         };          btn1.setontouchlistener(touchlistener);         btn2.setontouchlistener(touchlistener);      } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -