AndroidAnnotations——Listening to 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 {

        // ...

        @ItemClick
        public void myListItemClicked(MyItem clickedItem) {
        
        }
        
        @ItemLongClick
        public void myListItemLongClicked(MyItem clickedItem) {
        
        }

        @ItemSelect
        public void myListItemSelected(boolean selected, MyItem selectedItem) {
        
        }

}

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.
对于   @ItemClick @ItemLongClick  和 @ItemSelect 来说,如果参数是   int 类型的,那么适配器将传送位置值代替对象值。
@EActivity(R.layout.my_list)
public class MyListActivity extends Activity {

        // ...

        @ItemClick
        public void myListItemClicked(int position) {
        
        }
        
        @ItemLongClick
        public void myListItemLongClicked(int position) {
        
        }

        @ItemSelect
        public void myListItemSelected(boolean selected, int position) {
        
        }

}

可以和 AndroidAnnotations——Adapters and lists 适配器和列表 文档结合起来看

你可能感兴趣的:(AndroidAnnotations——Listening to AdapterViewEvents监听适配器视图事件)