-
Notifications
You must be signed in to change notification settings - Fork 2.3k
ClickEvents
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
).
AndroidAnnotations supports other kind of events, and it works exactly as with @Click
.
Currently, AndroidAnnotations supports the following events on views:
-
Clicks with
@Click
-
Long clicks with
@LongClick
-
Touches with
@Touch
19/11/2020 The 4.8.0 release is out !
- Get started!
- Cookbook, full of recipes
- Customize annotation processing
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow
- Ask on Gitter