简体   繁体   中英

MotionEvent.Action_UP fails

I am writing a simple code on ontouchevent..the code is

class MyTouchListener implements View.OnTouchListener{

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub

            if(event.getAction()==MotionEvent.ACTION_DOWN)
            {    Log.i(TAG, "^^^^^^^^^^^ACTION DOWN^^^^^^^^^^^^");
            }

            else if(event.getAction()==MotionEvent.ACTION_UP)
            {
                 Log.i(TAG, "^^^^^^^^^^^ACTION UP^^^^^^^^^^^^");
            }
}

while i pressed the screen it prints ^^^^^ACTION DOWN^^^^^ But when I released the screen it does not print ^^^^^^ACTION UP^^^^^^....

means MotionEvent.ACTION_UP fails..why this is so??

Try with MotionEvent.ACTION_CANCEL

 @Override
    public boolean onTouch(final View view, final MotionEvent motionEvent) {

        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                setColorFilter(Color.argb(155, 185, 185, 185));
        }
        else if (motionEvent.getAction() == MotionEvent.ACTION_UP || motionEvent.getAction() == MotionEvent.ACTION_CANCEL) {
                setColorFilter(Color.argb(0, 185, 185, 185));

        }
        return false;
    }

or add a log in your ontouch method Log.d("tag", "motionEvent=" + motionEvent);

well ACTION_DOWN is happening just once after that action move should be happening and in the and action up...

but there is one problem , for example if you have a touchable area of 48dip x 48dip and if you touch that area and move you finger away (while dragging) I mean you press and you drag you finger away from the touchable area than action up will not happen !!!

Action up will happen only in case when you take your finer of the screen but you are still in the touchable area. I hope you understand me what I am trying to say.

if you want mouse up to happen that touch the touchable area do not drag you finger away and take you finger away from the screen, you know just like taping then the up event will happen

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