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.

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.