AndroidAnnotation AdapterViewEvents
AdapterViewEvents适配器视图事件
Since AndroidAnnotations 1.0
You can bind methods to handle events on items in an AdapterView:
你可以绑定方法来处理适配器视图中项目的事件:
你可以绑定方法来处理适配器视图中项目的事件:
- Item clicks with
@ItemClick
- Long item clicks with
@ItemLongClick
- Item selection with
@ItemSelect
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)
.
加了
@ItemClick
和
@ItemLongClick
注解的方法必须有一个参数。这个参数可以是任何类型的,调用
adapter.getItem(position)
时返回一个object对象。
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.
加了
@ItemSelect
注解的方法可能有一个或两个参数。第一个参数必须是boolean类型,第二个参数是适配器中被选位置的对象。
@EActivity(R.layout.my_list) public class MyListActivity extends Activity { // ...@ItemClickpublic void myListItemClicked(MyItem clickedItem) { }@ItemLongClickpublic void myListItemLongClicked(MyItem clickedItem) { }@ItemSelectpublic void myListItemSelected(boolean selected, MyItem selectedItem) { }}
Since AndroidAnnotations 2.4
For@ItemClick
,@ItemLongClick
and@ItemSelect
, if the parameter is of typeint
, then the position is given instead of the object coming from the adapter.对于@ItemClick
,@ItemLongClick
和@ItemSelect
来说,如果参数是int
类型的,那么适配器将传送位置值代替对象值。
@EActivity(R.layout.my_list) public class MyListActivity extends Activity { // ...@ItemClickpublic void myListItemClicked(int position) { }@ItemLongClickpublic void myListItemLongClicked(int position) { }@ItemSelectpublic void myListItemSelected(boolean selected, int position) { }}
可以和 AndroidAnnotations——Adapters and lists 适配器和列表 文档结合起来看