Skip to content
Jon edited this page Jun 8, 2015 · 3 revisions

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

How to use

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

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

Notice it must return a boolean

Example

@OnItemLongClick(R.id.list)
public boolean onItemLongClick(int position) {
    Toast.makeText(this, "Item $position long-clicked", Toast.LENGTH_SHORT).show()
    return true
}

More information about return