One tap for more than one event

Asked

Viewed 59 times

3

I’m building a musical keyboard, and I’m having trouble making the next key sound if the user doesn’t take his finger off the screen.

Can someone help me with that?

 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();
            }
}
  • 2

    This can help you. http://www.survivingwithandroid.com/2012/08/multitouch-in-android.html

  • I found it so peaceful to learn the multi-touch as I could use it now to activate the same or other event? In other words, more than one key needs to be applied by swiping your finger across the screen without taking it off.

  • Did you get the answer you wanted? Or do you need something else?

  • Ah yes I got thank you was to produce this game https://play.google.com/store/apps/details?id=br.com.digital.onuse.xilofonenene

1 answer

4

You can explore more about Multi-touch Android, which is available from the Android 2.0 and was improved in the version 2.2.

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

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

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

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

inserir a descrição da imagem aqui

  • ACTION_DOWN is for the first finger that touches the screen. This starts the gesture. The pointer data for this finger is always in the index 0 in MotionEvent.
  • ACTION_POINTER_DOWN is for extra fingers entering the screen other than the first. The pointer data for this finger is in the index returned by getActionIndex().
  • ACTION_POINTER_UP is sent when the finger leaves the screen, but at least one finger is still touching it. The last sample of data on the finger that rose is in the index returned by getActionIndex().
  • ACTION_UP is sent when the last one leaves the screen finger. The last data sample on the finger that went up is in the index 0. This ends the gesture.
  • ACTION_CANCEL means the whole gesture was aborted for some reason. This ends the gesture.

Details

Browser other questions tagged

You are not signed in. Login or sign up in order to post.