博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Andorid之Annotation框架初使用(六)
阅读量:5949 次
发布时间:2019-06-19

本文共 5226 字,大约阅读时间需要 17 分钟。

EVENT

@Click :点击事件,只能有0个或1个参数,且参数为View   

@Click(R.id.myButton)void myButtonWasClicked() {    [...]}@Clickvoid anotherButton() {    [...]}@Clickvoid yetAnotherButton(View clickedView) {    [...]}

@LongClick
@Touch
AdapterViewEvents
@ItemClick 必须有一个参数,如果这个参数是object类型,意味着adapter.getItem(position) ; 如果是int ,意味着是position
@LongItemClick 必须有一个参数,如果这个参数是object类型,意味着adapter.getItem(position) ; 如果是int ,意味着是position
@ItemSelect 必须有一个或者两个参数,第一个参数必须是boolean 第二个参数为adapter.getItem(position) 或者也可以是int ,意味着是position

@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) {        }}

或者:

@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) {        }}

SeekBarEvents:
@OnSeekBarProgressChange

@SeekBarProgressChange(R.id.seekBar) void onProgressChangeOnSeekBar(SeekBar seekBar, int progress, boolean fromUser) {     // Something Here }  @SeekBarProgressChange(R.id.seekBar) void onProgressChangeOnSeekBar(SeekBar seekBar, int progress) {     // Something Here }  @SeekBarProgressChange({R.id.seekBar1, R.id.seekBar2}) void onProgressChangeOnSeekBar(SeekBar seekBar) {     // Something Here } @SeekBarProgressChange({R.id.seekBar1, R.id.seekBar2}) void onProgressChangeOnSeekBar() {     // Something Here }

@SeekBarTouchStart
@SeekBarTouchStop
以上两个标签的方法有0个或一个参数 , 一个参数类型为 SeekBar

@FocusChange

@FocusChange(R.id.helloTextView)void focusChangedOnHelloTextView(View hello, boolean hasFocus) {    // Something Here}@FocusChangevoid helloTextViewFocusChanged(View hello) {    // Something Here}@FocusChange({R.id.editText, R.id.helloTextView})void focusChangedOnSomeTextViews(View hello, boolean hasFocus) {    // Something Here}@FocusChange(R.id.helloTextView)void focusChangedOnHelloTextView() {    // Something Here}

@CheckedChange

@CheckedChange(R.id.helloCheckBox)void checkedChangeOnHelloCheckBox(CompoundButton hello, boolean isChecked) {    // Something Here}@CheckedChangevoid helloCheckBoxCheckedChanged(CompoundButton hello) {    // Something Here}@CheckedChange({R.id.aCheckBox, R.id.helloCheckBox})void checkedChangedOnSomeCheckBoxs(CompoundButton hello, boolean isChecked) {    // Something Here}@CheckedChange(R.id.helloCheckBox)void checkedChangedOnHelloCheckBox() {    // Something Here}

@TextChange

@TextChange(R.id.helloTextView) void onTextChangesOnHelloTextView(CharSequence text, TextView hello, int before, int start, int count) {     // Something Here }  @TextChange void helloTextViewTextChanged(TextView hello) {     // Something Here }  @TextChange({R.id.editText, R.id.helloTextView}) void onTextChangesOnSomeTextViews(TextView tv, CharSequence text) {     // Something Here }  @TextChange(R.id.helloTextView) void onTextChangesOnHelloTextView() {     // Something Here }

@BeforeTextChange

@BeforeTextChange(R.id.helloTextView) void beforeTextChangedOnHelloTextView(TextView hello, CharSequence text, int start, int count, int after) {     // Something Here }  @BeforeTextChange void helloTextViewBeforeTextChanged(TextView hello) {     // Something Here }  @BeforeTextChange({R.id.editText, R.id.helloTextView}) void beforeTextChangedOnSomeTextViews(TextView tv, CharSequence text) {     // Something Here }  @BeforeTextChange(R.id.helloTextView) void beforeTextChangedOnHelloTextView() {     // Something Here }

@AfterTextChange

@AfterTextChange(R.id.helloTextView) void afterTextChangedOnHelloTextView(Editable text, TextView hello) {     // Something Here }  @AfterTextChange void helloTextViewAfterTextChanged(TextView hello) {     // Something Here }  @AfterTextChange({R.id.editText, R.id.helloTextView}) void afterTextChangedOnSomeTextViews(TextView tv, Editable text) {     // Something Here }  @AfterTextChange(R.id.helloTextView) void afterTextChangedOnHelloTextView() {     // Something Here }

Option Menu:

@EActivity@OptionsMenu(R.menu.my_menu)public class MyActivity extends Activity {    @OptionMenuItem    MenuItem menuSearch;    @OptionsItem(R.id.menuShare)        void myMethod() {          // You can specify the ID in the annotation, or use the naming convention        }    @OptionsItem    void homeSelected() {      // home was selected in the action bar          // The "Selected" keyword is optional    }    @OptionsItem    boolean menuSearch() {          menuSearch.setVisible(false);          // menuSearch was selected          // the return type may be void or boolean (false to allow normal menu processing to proceed, true to consume it here)          return true;    }    @OptionsItem({ R.id.menu_search, R.id.menu_delete })    void multipleMenuItems() {      // You can specify multiple menu item IDs in @OptionsItem    }    @OptionsItem    void menu_add(MenuItem item) {      // You can add a MenuItem parameter to access it    }}

转载地址:http://tlfxx.baihongyu.com/

你可能感兴趣的文章
RancherOS v0.8.0发布:支持离线安装,更佳部署体验
查看>>
AI+社交,快手商业化落地之道
查看>>
Microsoft Graph:连接每个应用都需要的基础数据
查看>>
Latex格式html文件转换pdf和docx文档
查看>>
【关于Number】JavaScript中关于Number的操作
查看>>
非泄露,NSA官方开源反汇编工具GHIDRA
查看>>
保持分布式团队同步
查看>>
Node.js v7 Beta版引入citgm
查看>>
微服务没有银弹 | Weibo Mesh 的工程化实践解读
查看>>
让你的系统“坚挺不倒”的最后一个大招——「降级」
查看>>
Git 2.5增加了工作树、改进了三角工作流、性能等诸多方面
查看>>
搭载AI引擎,腾讯云云镜开启全面防护模式
查看>>
不仅有Ubuntu,这家公司的Ubuntu Core预计使用翻倍
查看>>
JMS机制
查看>>
Grumpy:Google 用 Go 开发的 Python 运行时
查看>>
Kubernetes 1.14 版本发布:正式支持Windows 节点,持久化本地卷进入GA
查看>>
区块链和数据科学:如果同时应用这两种技术,将会实现什么?
查看>>
AVG插件泄漏Chrome用户数据
查看>>
免费微信公众号专用h5在线电影票API
查看>>
专访刘刚:360手机卫士的性能监控与优化
查看>>