ClickEvents - shiraji/androidannotations GitHub Wiki

@Click

Since AndroidAnnotations 1.0

The @Click annotation indicates that an activity method must be called when the corresponding view is clicked.

The view id can be set in the annotation parameter, ie @Click(R.id.myButton). If the same method handles multiple views, multiple view ids can be given in the following format: @Click({R.id.myButton, R.id.myOtherButton}).

If the view id is not set, the name of the method will be used to guess the view id.

The method may have zero or one parameter, and this parameter can only be a View (the view that was clicked). The method must not be private. Two different methods cannot handle the same view.

Usage example:

@Click(R.id.myButton)
void myButtonWasClicked() {
    [...]
}

@Click
void anotherButton() {
    [...]
}

@Click
void yetAnotherButton(View clickedView) {
    [...]
}

@Click({R.id.myButton, R.id.myOtherButton})
void handlesTwoButtons() {
    [...]
}

Since AndroidAnnotations 4.0

As of AndroidAnnotations 4.0 any subclass of View can be passed to the methods (eg. Button).

Other events

AndroidAnnotations supports other kind of events, and it works exactly as with @Click.

Currently, AndroidAnnotations supports the following events on views: