I am using android-annotations for a sample project and trying to learn it, but i came up with a strange thing.
Assume that we have a simple button named "@+id/button"
Now i want to write two seperate methods for touch and click events.
@Touch
public void button(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
v.setAlpha(0.5f);
} else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
v.setAlpha(1f);
}
}
@Click
public void button() {
startActivity(new Intent(this, ExampleActivity.class));
finish();
}
When i run the project, i see the touch event, but click event will never be caught. Am i missing something, may be conceptual ?
The method annotated by @Touch can return an boolean indicating whether the event is consumed. So you can replace the method
@Touch
public void button(View v, MotionEvent event) {
...
}
by
@Touch
public boolean button(View v, MotionEvent event) {
...
return false;
}