简体   繁体   中英

OnTouch with multitouch in android

I am havig troubles counting how much touches are being made in each "half" of the screen. When I touch in the upper side it counts correctly, and the same with the lower side. BUT, when I touch the upper side, dont release it, and touch the lower side, then it counts the wrong side, what is wrong in my implementation?

     myView.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                int action = event.getAction() & MotionEvent.ACTION_MASK;
                if (action == MotionEvent.ACTION_DOWN) {
                    if(event.getY()<400)
                    {


                    }
                    else
                    {

                    }
                }

                if (action == MotionEvent.ACTION_UP) {

                    if(event.getY()<400)
                    {

                        zenbat=zenbat+1;
                        tv.setText(String.valueOf(zenbat));

                    }
                    if(event.getY()>400)
                    {
                        zenbat1=zenbat1+1;
                        tv1.setText(String.valueOf(zenbat1));

                    }
                }

                if (action == MotionEvent.ACTION_POINTER_DOWN) {
                    if(event.getY()<400)
                    {                           
                    }
                    else
                    {
                    }
                }

                if (action == MotionEvent.ACTION_POINTER_UP) {
                    if(event.getY()<400)
                    {
                        zenbat=zenbat+1;
                        tv.setText(String.valueOf(zenbat));

                    }
                    if(event.getY()>400)
                    {
                        zenbat1=zenbat1+1;
                        tv1.setText(String.valueOf(zenbat1));

                    }
                } 
                return true;
            }
        });

If you want to correctly handle multitouch events you need to use the pointer index to correctly identify the finger generating the event.

I've answered a similar question in Android multi-touch interference where I posted a code example how to do it.

To correctly identify the finger, you should refer to the fingerId in the code posted.

Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM