One touch for more than one event

3

I'm building a music keyboard, and I'm having trouble playing the next key sound if the user does not take my finger off the screen.

Can anyone help me with this?

 botao1.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            if (event.getAction() == MotionEvent.ACTION_DOWN ) {
                posicao = 0;
                som.seekTo(posicao);
                som.start();
            }
}
    
asked by anonymous 29.09.2016 / 08:28

1 answer

4

You can explore more about # , which has been available since Android 2.0 and has been enhanced in version 2.2 .

The MotionEvent.ACTION_POINTER_DOWN and MotionEvent.ACTION_POINTER_UP are sent from the second finger. For the first finger and MotionEvent.ACTION_DOWN and MotionEvent.ACTION_UP are used.

The method getPointerCount() in MotionEvent allows to determine the number of indications on the device. All events and pointer positions are included in the MotionEvent instance that you receive in the OnTouch() method.

To track touch events from various tips you have to use the MotionEvent.getActionIndex() and MotionEvent.getActionMasked() methods to identify the pointer index and the touch event that happened to this pointer.

This pointer index may change over time if a finger is lifted from the device. See the image of the points pressed:

  • ACTION_DOWNisforthefirstfingerthattouchesthescreen.Thisstartsthegesture.Thepointerdataforthisfingerisalwaysat%index%with0.
  • MotionEventisfortheextrafingersthatenterthescreenbeyondthefirst.ThepointerdataforthisfingerisintheindexreturnedbyACTION_POINTER_DOWN.
  • getActionIndex()issentwhenthefingerleavesthescreen,butatleastonefingerisstilltouchingit.ThelastsampleofdataontheraisedfingerisintheindexreturnedbyACTION_POINTER_UP.
  • getActionIndex()issentwhenthelastoneleavesthefingerscreen.ThelastsampleofdataontheraisedfingerisattheACTION_UPindex.Thisendsthegesture.
  • 0meansthewholegesturewasabortedforsomereason.Thisendsthegesture.

Details

29.09.2016 / 14:53