Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

InferringIDFromMethodName

Csaba Kozák edited this page Sep 30, 2015 · 2 revisions

With event binding annotations, like @Click or @ItemClick it is not necessary to pass the resource ID as an annotation parameter. In that case, AndroidAnnotations can infer the resource ID from the method name.

For example the method:

@Click
void loginButtonClicked() {

}

will generate a listener which will be set up on the View with ID R.id.loginButton.
You can use use two types of notations for method names:

  • <resourceID>()
  • <resourceId><actionName>()

The actionName is derived from the annotation name, for example it is Clicked for @Click or Touched for @Touch.

If you prefer to use snake_case for your resource names, but still you want to use the standard Java camelCase for method names, that is no problem: AndroidAnnotations can convert camel case method names to snake case resource IDs. For example:

@Click
void loginButtonClicked() {

}

will work if the ID name is R.id.login_button.

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally