Android - onTouchListener with count -
i want button launch settings activity after 3rd click. right not working @ all. how can that?
((button)findviewbyid(r.id.einstellungen)).setontouchlistener(new view.ontouchlistener() { int counter = 0; @override public boolean ontouch(view v, motionevent event) { counter++; if(counter==3) { switch (event.getaction()) { case motionevent.action_down: { button view = (button) v; view.getbackground().setcolorfilter(0x77000000, porterduff.mode.src_atop); v.invalidate(); break; } case motionevent.action_up: intent intent = new intent(fullscreenactivity.this, settings.class); startactivity(intent); case motionevent.action_cancel: { button view = (button) v; view.getbackground().clearcolorfilter(); view.invalidate(); break; } } } homecoming true; } });
currently counter increased every touch action. illustration if place finger on screen (+1) drag bit (+2-5) move finger off screen (+1 ) counter more 3 , if block not reached.
i advise utilize click listener that:
((button)findviewbyid(r.id.einstellungen)).setonclicklistener(new view.onclicklistener() { int counter = 0; @override public void onclick(view view) { ++counter; if (counter == 3) { intent intent = new intent(fullscreenactivity.this, settings.class); startactivity(intent); // reset counter (if want to) counter = 0; } } });
that way can maintain other functionality in ontouch
, still able start other activity after 3 clicks have been registered.
note: remember remove counter logic ontouch listener , remove startactivity action_up event.
android ontouchlistener
No comments:
Post a Comment