AndroidAnnotations——Listening to AdapterViewEvents监听适配器视图事件

AdapterViewEvents适配器视图事件

Since AndroidAnnotations 1.0


You can bind methods to handle events on items in an AdapterView:
你可以绑定方法来处理适配器视图中项目的事件:

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 适配器和列表 文档结合起来看

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值