AndroidAnnotations——Listening to AdapterViewEvents监听适配器视图事件
2013-12-07 20:37
447 查看
AdapterViewEvents适配器视图事件
Since AndroidAnnotations 1.0You 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
@ItemClickor
@ItemLongClickmust
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
@ItemSelectmay
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,
@ItemLongClickand
@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监听适配器视图事件
- Android 解析RecyclerView(1)——带点击事件监听的通用Adapter
- java.lang.ClassCastException: android.widget.HeaderViewListAdapter cannot be cast to com.android.mms
- Android 带点击事件的RecyclerView所用Adapter
- Android初级知识--ViewPager适配器:PagerAdapter和FragmentPagerAdapter的最基本使用
- Android ViewPager+Handler实现无限轮播和监听处理事件时轮播速度越来越快的问题解决
- Android实战简易教程-第四枪(ScrollView和HorizontalScrollView动态添加控件并提供事件监听)
- Android 在XML文件中添加View点击事件的监听:OnClickListener
- Android 开源框架BaseRecyclerViewAdapterHelper使用——RecyclerView万能适配器
- Android之自定义View的监听事件
- Android数据适配器(Adapter)优化:使用高效的ViewHolder
- Android ListView适配器Adapter的使用,item的复用和ViewHolder优化
- Android:ListView、BaseAdapter、convertView、ListView优化及事件、notifyDataSetChanged()
- Android中监听Phonegap的webview的start,finish等事件
- Android:ViewPager适配器PagerAdapter的使用
- cannot be cast to android.widget.HeaderViewListAdapter
- Android 监听视图创建完成,避免Unable to add window..错误
- Android 触摸事件监听(Activity层,ViewGroup层,View层)详细介绍
- android中ListView中在Adapter中为Button设置监听事件方法--跳转Activity
- Android中ListView与适配器ArrayAdapter,SimpleAdapter,定义BaseAdapter适配器,ListView添加headerView,ListView滚动到最后一项