views:

307

answers:

2

Hello guys.

I'm working on an android application, and test it on an emulator, because I don't have physical android device.

So, I have a button, and I set a click listener on it. Does it mean that it will work only when the user pushes the click button on his device, or it will work also when he taps the button (the tap is touch event right?)? Also when I set a touch listener to the button, and when I click with the cursor on the button (on the emulator), it fires the two events onClick and onTouch.

Do I need to have the two listeners, because I want to work on click and touch, but I don't know its behavior on a real device.

Thank you.

+2  A: 

Does it mean that it will work only when the user pushes the click button on his device, or it will work also when he taps the button (the tap is touch event right?)?

It will also work when the user tap the button.

Do I need to have the two listeners, because I want to work on click and touch, but I don't know its behavior on a real device.

Usually, you just have to use the click listener. So, you may wonder when to use the touch listener. Well, generally touch events gives you the coordinates of that touch, so that you can decide what to do depending on those coordinates. In your case, and most of the cases, the only important thing is that the user click the button, rather than in which part of the button.

Cristian
Thanks. One more question in this context.Does this means also for an extended View?
I've been agonising over this for a while (no actual phone either). Good question, useful answer. +1 for both
NickT
A: 

One onClickListener should handle both a touch event and a trackball click event. You don't need a physical device to test this, you can click your emulator's screen or click the trackball.

Brandon