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开发者_Python百科 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
精彩评论