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 with a click. I mean, if I use a mouse to click, for example, I don’t want the onTouch event attached to the ImageButton to be fired. However it IS fired when you click the mouse over the button.
Is it possible to fire the event JUST when a touch happens?
My code:
myImageButton.setOnTouchListener(new Button.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent arg1) {
if (arg1.getAction() == android.view.MotionEvent.ACTION_DOWN) {
Toast.makeText(LiVoiceActivity.this,
"You touched me!",
Toast.LENGTH_LONG).show();
}
return true;
}
});
Thank you!
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
API 9
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.