Skip to content
dexafree edited this page Aug 21, 2014 · 3 revisions

This annotation will trigger an event when an AbsListView (ListView, GridView...) item is clicked.

How to use

The method should be this way (the method and variable names can be changed):

  • public void onItemClick(int position)
  • public void onItemClick(int position, AdapterView adapterView)
  • public void onItemClick(int position, AdapterView adapterView, View clickedView)

Example

@OnItemClick(R.id.list)
public void onItemClick(int position) {
    Toast.makeText(this, "Item $position clicked", Toast.LENGTH_SHORT).show();
}