<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## (一).前言: 前面我們已經對于AndroidAnnotations框架的Injection標簽做了講解,今天我們開始具體學習一下事件綁定方法(Event Binding)。 FastDev4Android框架項目地址:[https://github.com/jiangqqlmj/FastDev4Android](https://github.com/jiangqqlmj/FastDev4Android)? 已更新如下: ![](https://box.kancloud.cn/2016-01-18_569c8eb27e195.jpg) ## (二).@TextChange 該注解用戶定義當TextView或者TextView的子類中的文本發生改變回調事件方法anroid.text.TextWatcher.onTextChanget(CharSequence s,int start,intbefore,int count)來進行處理。該注解的參數值為一個或者多個TextView或者該子類的R.id.*引用。如果沒有設置,那么方法名字將會作為R.id.*屬性名稱。該方法中可以有多個參數。 * android.widget.TextView注解知道那個view接收到了事件 * Java.lang.CharSequence可以獲取到發生改變的文本 * Intstart表示改變文本的起始位置 * Intbefore表示文本修改之前的長度 * Intcount表示文本修改的數量 下面就是使用實例: ~~~ @TextChange(R.id.helloTextView) void onTextChangesOnHelloTextView(CharSequencetext, 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 該用來注解回調TextView或者TextView子類文本發生變化之前的方法android.text.TextWathcher.beforeTextChanged(CharSequences,int start, int count,int after). 使用實例如下: ~~~ @BeforeTextChange(R.id.helloTextView) void beforeTextChangedOnHelloTextView(TextViewhello, CharSequence text, int start, int count, int after) { // Something Here } @BeforeTextChange void helloTextViewBeforeTextChanged(TextViewhello) { // Something Here } @BeforeTextChange({R.id.editText,R.id.helloTextView}) void beforeTextChangedOnSomeTextViews(TextViewtv, CharSequence text) { // Something Here } @BeforeTextChange(R.id.helloTextView) void beforeTextChangedOnHelloTextView() { // Something Here } ~~~ ## (四).@AfterTextChange 該用來注解回調TextView或者TextView子類文本發生變化之后的方法android.text.TextWathcher.afterTextChanged(Editable s) 使用實例如下: ~~~ @AfterTextChange(R.id.helloTextView) void afterTextChangedOnHelloTextView(Editabletext, TextView hello) { // Something Here } @AfterTextChange void helloTextViewAfterTextChanged(TextViewhello) { // Something Here } @AfterTextChange({R.id.editText,R.id.helloTextView}) void afterTextChangedOnSomeTextViews(TextViewtv, Editable text) { // Something Here } @AfterTextChange(R.id.helloTextView) void afterTextChangedOnHelloTextView() { // Something Here } ~~~ ## (五).@EditorAction 自AndroidAnnotations3.1起 該注解用來處理android.widget.TextView.OnEditorActionListener#onEditorAction(android.widget.TextView,int,android.View.KeyEvent)回調的事件.當接收處理編輯事件時候。 該注解的參數值為一個或者多個TextView或者該子類的R.id.*引用。如果沒有設置,那么方法名字將會作為R.id.*屬性名稱。該方法中可以有多個參數。 * Android.widget.TextView參數表示該接收到事件的view * Int參數表示事件動作的action * android.view.KeyEvent表示具體的事件 該方法返回的類型為void或者boolean。boolean返回true或者false表示當前事件是否被消費掉。如果返回void那么總會返回true給監聽器,表示事件已經被消費掉了。 實例如下: ~~~ @EditorAction(R.id.helloTextView) void onEditorActionsOnHelloTextView(TextViewhello, int actionId, KeyEvent keyEvent) { // Something Here } @EditorAction void helloTextViewEditorAction(TextViewhello) { // Something Here } @EditorAction({R.id.editText,R.id.helloTextView}) void onEditorActionsOnSomeTextViews(TextViewtv, int actionId) { // Something Here } @EditorAction(R.id.helloTextView) void onEditorActionsOnHelloTextView() { // Something Here } @EditorAction(R.id.helloTextView) boolean onEditorActionsOnHelloTextView() { // Something Here return false; } ~~~ ## (六).@FocusChange 該注解用來定義方法當view的焦點狀態發生的改變的時候回調android.view.View.OnFoucChangeListener(View?view,boolean hasFocus)的方法來處理事件。 * android.viw.View參數表示接受事件的view * hasFocus boolean表示獲取或者失去焦點 下面是使用@FocusChange注解的實例: ~~~ @FocusChange(R.id.helloTextView) voidfocusChangedOnHelloTextView(View hello, boolean hasFocus) { // Something Here } @FocusChange voidhelloTextViewFocusChanged(View hello) { // Something Here } @FocusChange({R.id.editText,R.id.helloTextView}) voidfocusChangedOnSomeTextViews(View hello, boolean hasFocus) { // Something Here } @FocusChange(R.id.helloTextView) voidfocusChangedOnHelloTextView() { // Something Here } ~~~ ## (七).@CheckedChange 該注解用來定義處理當compound button狀態發生改變的時候回調android.widget.CompoundButton.OnCheckedChangeListener.onCheckedChanged(CompoundButtonbuttonView,boolean isChecked)方法來處理事件; * android.widget.CompoundButton該參數表示接受事件的compound button * isChecked參數表示view是否被選中 下面為@CheckedChange注解的使用實例 ~~~ @CheckedChange(R.id.helloCheckBox) voidcheckedChangeOnHelloCheckBox(CompoundButton hello, boolean isChecked) { // Something Here } @CheckedChange voidhelloCheckBoxCheckedChanged(CompoundButton hello) { // Something Here } @CheckedChange({R.id.aCheckBox,R.id.helloCheckBox}) voidcheckedChangedOnSomeCheckBoxs(CompoundButton hello, boolean isChecked) { // Something Here } @CheckedChange(R.id.helloCheckBox) voidcheckedChangedOnHelloCheckBox() { // Something Here } ~~~ ## (八).@Click 該@Click注解的方法當相關的view被進行點擊的時候會進行回調進行處理。被點擊的view的id可以設置成注解的參數;例如:@Click(R.id.myButton) 如果同樣的方法來處理多個view事件,多個view的ids可以如下進行設置 @Click({R.id.myButton,R.id.myOtherButton}) 如果view的id沒有設置,那么默認會使用方法的名字作為view的id; 該方法可能會有一個或者沒有參數,如果存在參數那么參數只可能是一個view(該被點擊的view)。該方法不能為私有方法,兩個不同的方法不能處理同樣的view。 使用實例如下: ~~~ @Click(R.id.myButton) voidmyButtonWasClicked() { [...] } @Click void anotherButton(){ [...] } @Click voidyetAnotherButton(View clickedView) { [...] } @Click({R.id.myButton,R.id.myOtherButton}) voidhandlesTwoButtons() { [...] } ~~~ ## (九).@ItemClick,@ItemLongClick,@ItemSelect 你可以綁定方法來處理AdapterView中item的事件 * Item Clicks使用@ItemClick * Long?Item Clicks使用@ItemLongClick * Item selection使用@ItemSelect 該注解的參數可以為一個或者多個R.id.*,如果沒有設置方法的名字會默認作為R.id.* * 如果采用@ItemClick或者@ItemLongClick注解的方法必須要有一個參數,該參數為當調用adapter.getItem(positon)返回的對象的類型。? * 如果采用@ItemSelect注解的方法可能有一個或者兩個參數,第一個參數必須要為boolean類型,第二個參數為adapter中選中位置的對象 使用實例如下: ~~~ @EActivity(R.layout.my_list) public classMyListActivity extends Activity { // ... @ItemClick public void myListItemClicked(MyItemclickedItem) { } @ItemLongClick public void myListItemLongClicked(MyItemclickedItem) { } @ItemSelect public void myListItemSelected(booleanselected, MyItem selectedItem) { } } ~~~ 自Androidannotations2.4器 [注]對于@ItemClick,@ItemLongClick和@ItemSelect注解的方法,如果參數的類型為int,那么該代表選中索引position而不是代表adpter中選中的對象,實例如下: ~~~ @EActivity(R.layout.my_list) public classMyListActivity extends Activity { // ... @ItemClick public void myListItemClicked(int position){ } @ItemLongClick public void myListItemLongClicked(intposition) { } @ItemSelect public void myListItemSelected(booleanselected, int position) { } } ~~~ ## (十).@OptionsItem 10.1.處理可選菜單 自AndroidAnnotations2.2起 通過@OptionsMenu和@OptionsItem注解你可以在Activity中很快添加菜單功能。 * @OptionsMenu表示菜單資源 * @OptionsItem標示選中某個菜單 下面是一個簡單的例子: ~~~ @EActivity @OptionsMenu(R.menu.my_menu) public classMyActivity extends Activity { @OptionsMenuItem MenuItem menuSearch; @OptionsItem(R.id.menuShare) void myMethod() { // You can specify the ID in theannotation, or use the naming convention } @OptionsItem void homeSelected() { // home was selected in the action bar // The "Selected" keyword isoptional } @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 IDsin @OptionsItem } @OptionsItem void menu_add(MenuItem item) { // You can add a MenuItem parameter toaccess it } } ~~~ 10.2.注入菜單項 自AndroidAnnotations3.0起 @OptionsMenuItem可以在屬性中進行注入一個MenuItem 【注】由于Activity生命周期的原因,注入的menuitem是不能在@AfterInject或者@AfterView注解的方法中進行使用。 10.3.注入菜單 自AndroidAnnotations4.0開始 @OptionsMenuItem可以在在Fragment或者Activity中注入Menu對象 【注】該menu和@OptionsMenuItem一樣,不能在@AfterInject或者@AfterView注解的方法中進行使用。 使用實例如下: ~~~ @EActivity public classMyActivity extends Activity { @InjectMenu Menu menu; } ~~~ 10.4.多個可選菜單 自AndroidAnnotations2.7起,可以使用@OptionsMenu來進行聯合多個xmlmenus注入多個可選菜單 ~~~ @EActivity @OptionsMenu({R.menu.my_menu1,R.menu.my_menu2}) public classMyActivity extends Activity { } ~~~ 10.5.Fragment支持 自AndroidAnnotations2.7起,你可以在Fragment中使用@OptionsMenu和@OptionsItem ~~~ @EFragment @OptionsMenu(R.menu.my_fragment_menu) public classMyFragment extends Fragment { @OptionsItem void menuRefreshSelected() { } } ~~~ ## (十一).@SeekBarProgressChange 我們可以綁定方法來處理來自SeekBarView的方法。使用@SeekBarProgressChange注解的方法等同于當SeekBar的進度發生改變的時候回調SeekBar.onSeekBarChangeListener.onProgressChanged(SeekBar,int,boolean)方法來處理事件。參數說明 * Android.widget.SeekBar參數表示接受的事件的view * int參數表示SeekBar的進度 * boolean參數表示是否由用戶觸發 以上所有的這些參數都可以可選的,使用實例如下: ~~~ @SeekBarProgressChange(R.id.seekBar) void onProgressChangeOnSeekBar(SeekBarseekBar, int progress, boolean fromUser) { // Something Here } @SeekBarProgressChange(R.id.seekBar) void onProgressChangeOnSeekBar(SeekBarseekBar, int progress) { // Something Here } @SeekBarProgressChange({R.id.seekBar1,R.id.seekBar2}) void onProgressChangeOnSeekBar(SeekBarseekBar) { // Something Here } @SeekBarProgressChange({R.id.seekBar1,R.id.seekBar2}) void onProgressChangeOnSeekBar() { // Something Here } ~~~ ## (十二).@SeekBarTouchStart,@SeekBarTouchStop 這兩個注解方法等同于當用戶開始或者完成對SeekBar的拖動回調SeekBar.onSeekBarChangeListener.onStartTrackingTouch(SeekBarseekBar)和SeekBar.OnSeekBarChangeListener.onStopTrackingTouch(SeekBar seekBar)方法來處理事件。 ## (十三).@KeyDown,@KeyUp,@KeyLongPress,@KeyMultiple 13.1.事件介紹 自AndroidAnnotations4.0開始。你可以很方便的處理KeyEvent.Callback接口中的四個事件。更多信息可以查看KeyEevent.Callback文檔。四個事件的注入如下: * @KeyDown * @KeyUp * @KeyLongPress * @KeyMultiple 這四個注解可以在參數中設置keycode或者keycodes。通過KeyEvent.KEYCODE_*常量也可以設置。例如:KeyDown(KeyEevent.KEYCODE_ENTER)或者KeyDown({}) 如果這個key code沒有被設置,那么方法的名字默認用于key code。如果回車事件被調用,那么可能回調用的事件有enter,onEnter,enterPressed,onEnterPressed。所有的被注解的方法都可以返回void,boolean或者Boolean,如果返回void,那么將永遠返回true(該代表已經處理事件) 13.2.@KeyDown,@KeyUp,@KeyLongPress 該被注解的方法考可以為一個或者零個參數。如果沒有參數也必須為KeyEvent。該方法不能為私有,兩個不同的方法在一個類中不能處理同一個事件,使用實例: ~~~ @EActivity public classMyActivity extends Activity { @KeyDown void enterPressed() { //... } @KeyUp(KeyEvent.KEYCODE_ESCAPE) boolean handleEscapeActionUpEvent() { //... return false; } @KeyLongPress({ KeyEvent.KEYCODE_F,KeyEvent.KEYCODE_G }) void fOrGKeyLongPress(KeyEvent keyEvent) { //... } } ~~~ 13.3.@KeyMultiple 該被注解的方法可以沒有參數,一個或者兩個參數。 使用實例如下: ~~~ @EActivity public classMyActivity extends Activity { @KeyMultiple void onEnterPressed() { //... } @KeyMultiple(KeyEvent.KEYCODE_ESCAPE) boolean handleEscapeActionMultipleEvent(intcount) { //... return false; } @KeyMultiple({ KeyEvent.KEYCODE_F,KeyEvent.KEYCODE_G }) void fOrGKeyWasMultiplePressed(int count,KeyEvent keyEvent) { //... } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看