Getting Just The Ontouch Event (android)
I am trying to separate a few things in here. I have a program with Imagebuttons. They have onTouchListeners attached to them. I wish touch event to be fired JUST with a touch, not
Solution 1:
There's a field known as a Tool_Type in the MotionEvent class. I have implemented a check for the mouse type here:
API 14 AKA EASY MODE
myImageButton.setOnTouchListener(newButton.OnTouchListener() {
@OverridepublicbooleanonTouch(View v, MotionEvent arg1) {
if (arg1.getAction() == android.view.MotionEvent.ACTION_DOWN
&& (MotionEvent.TOOL_TYPE_MOUSE != arg1.getToolType(0)) {
Toast.makeText(LiVoiceActivity.this,
"You touched me!",
Toast.LENGTH_LONG).show();
}
returntrue;
}
});
API 9
myImageButton.setOnTouchListener(newButton.OnTouchListener() {
@OverridepublicbooleanonTouch(View v, MotionEvent arg1) {
if (arg1.getAction() == android.view.MotionEvent.ACTION_DOWN
&& (arg1.getSize() > 1) {
Toast.makeText(LiVoiceActivity.this,
"You touched me!",
Toast.LENGTH_LONG).show();
}
returntrue;
}
});
Now this checks the size of the MotionEvent received. PRESUMABLY, a mouse click would have a size of 1, therefore, only recognize sizes bigger than 1. Play around with that number and see if you can differentiate between the mouse and finger touch.
Post a Comment for "Getting Just The Ontouch Event (android)"