PointsToPonder
PointsToPonder

Reputation: 171

Android onTouch(View,MotionEvent) not called but onTouchEvent(MotionEvent event) is called?

Does anyone know why my logs indicate that onTouch(View, MotionEvent) does not get called. I can see that onTouchEvent(MotionEvent event) is being called. Both are overridden in Activity which implements View.OnTouchEvent.

Upvotes: 1

Views: 9282

Answers (3)

Abner Niu
Abner Niu

Reputation: 405

onTouch() is called when a View is touched,but onTouchEvent() is called when the Activity (the screen) is touched.

When the return value of onTouch() is true, the touch event will be comsumed by the onTouch(), otherwise, the event will be delivered to the onTouchEvent().

Hope it's useful for you.

Upvotes: 4

Peter Knego
Peter Knego

Reputation: 80340

AFAIK, Activity does not define onTouch(..), but it does define onTouchEvent(..). So you are overriding the latter, but merely defining the former.

Also, the onTouchEvent(..) is a last resort touch handler - it gets called only if views do not handle it:

onTouchEvent(MotionEvent event)
Called when a touch screen event was not handled by any of the views under it.

Upvotes: 3

user1213202
user1213202

Reputation: 1305

onTouch can be used in android.some thing like this use in ur activity.no need to override

      ed.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "hai",   Toast.LENGTH_LONG).show();
                return false;
            }
        });

Upvotes: 0

Related Questions