ClickEvents

Csaba Kozák edited this page Mar 16, 2016 · 6 revisions

@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.0

As of AndroidAnnotations 4.0.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:

14/10/2018 The 4.5.1 release is out !

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.