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

AdapterViewEvents

WonderCsabo edited this page Nov 10, 2014 · 6 revisions

Since AndroidAnnotations 1.0

You can bind methods to handle events on items in an AdapterView:

The annotation value should be one or several of R.id.* fields. If not set, the method name will be used as the R.id.* field name.

Methods annotated with @ItemClick or @ItemLongClick must have one parameter. This parameter can be of any type, it's the object retrieved when calling adapter.getItem(position).

Methods annotated with @ItemSelect may have one or two parameters. The first parameter must be a boolean, and the second is the object from the adapter, at the selected position.

@EActivity(R.layout.my_list)
publicclassMyListActivityextendsActivity {
// ...@ItemClickpublicvoidmyListItemClicked(MyItemclickedItem) {
}
@ItemLongClickpublicvoidmyListItemLongClicked(MyItemclickedItem) {
}
@ItemSelectpublicvoidmyListItemSelected(booleanselected, MyItemselectedItem) {
}
}

Since AndroidAnnotations 2.4

For @ItemClick, @ItemLongClick and @ItemSelect, if the parameter is of type int, then the position is given instead of the object coming from the adapter.

@EActivity(R.layout.my_list)
publicclassMyListActivityextendsActivity {
// ...@ItemClickpublicvoidmyListItemClicked(intposition) {
}
@ItemLongClickpublicvoidmyListItemLongClicked(intposition) {
}
@ItemSelectpublicvoidmyListItemSelected(booleanselected, intposition) {
}
}

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally