5

I have to take count for the total number of fingers clicked on screen.

Used Touch event as below :

relTouch.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch(event.getPointerCount()){
                case 1:
                    Toast.makeText(MainActivity.this, "Single touch", Toast.LENGTH_SHORT).show();
                    break;
                case 2:
                    Toast.makeText(MainActivity.this, "Double touch", Toast.LENGTH_SHORT).show();
                    break;
                case 3:
                    Toast.makeText(MainActivity.this, "Triple touch", Toast.LENGTH_SHORT).show();
                    break;
            }
            return true;
        }

    });

It's working fine.

But, The issue is When I tap with more than one finger, It also giving me single click. If I tap with 3 fingers, it also gives me Single and Double click.

How to solve this ?

Jaimin Modi
  • 1,530
  • 4
  • 20
  • 72
  • Correct me If I am wrong, it is a touch listener. So it counts when there is a touch. What do you mean more than one finger ? It wont count number of fingers, right ? – cantona_7 Jul 31 '19 at 10:46
  • getPointerCount() returns number of fingers. The current number of pointers can be obtained via a call to the getPointerCount() method of the current MotionEvent object. – Jaimin Modi Jul 31 '19 at 10:53
  • The pointer index of each pointer in the event ranges from 0 to one less than the value returned by getPointerCount(). Did you read `android developer guide`. I am just trying to understand here. – cantona_7 Jul 31 '19 at 10:57
  • This what suggested in `developer guide`. Have a look https://developer.android.com/reference/android/view/MotionEvent#getPointerCount() – cantona_7 Jul 31 '19 at 11:01
  • @cantona_7 Have you understand sir, What we need to change here...? – Jaimin Modi Jul 31 '19 at 11:26
  • Anyone here to look in to issue and resolve ? – Jaimin Modi Aug 01 '19 at 06:03

0 Answers0