天天看點

AndroidAnnotations學習筆記--事件(三)

[size=large][color=red][b]@TextChange[/b][/color][/size]

這個注解是用于接收 [i]android.text.TextWatcher.onTextChanged(CharSequence s, int start, int before, int count)[/i] Android定義的事件。

未使用@TextChange之前,我們的代碼要這樣寫:

使用這個注解之後我們的代碼可以按下面的幾種方式寫:

支援多種的輸入參數

[i]@TextChange({R.id.edit_test, R.id.helloTextView})[/i]

支援多個View綁定一個BeforeTextChange

[i]@TextChange void helloTextViewTextChanged(TextView edit_test)[/i]

可以在參數中指定View

[size=large][color=red][b]@BeforeTextChange[/b][/color][/size]

這個注解是用于接收 [i]android.text.TextWatcher.beforeTextChanged(CharSequence s, int start, int count, int after)[/i] Android定義的事件。

未使用@BeforeTextChange注解之前我們這樣寫代碼

使用這個注解之後,我們可以按以下的多種方法寫:

支援多種的輸入參數

[i]@BeforeTextChange({R.id.edit_test, R.id.helloTextView})[/i]

支援多個View綁定一個BeforeTextChange

[i]@BeforeTextChange void helloTextViewBeforeTextChanged(TextView edit_test)[/i]

可以在參數中指定View

[size=large][color=red][b]@AfterTextChange[/b][/color][/size]

這個注解是用于接收 [i]android.text.TextWatcher.afterTextChanged(Editable s)[/i] Android定義的事件。

沒使用@AfterTextChange這個注解之前我們的代碼是這樣的

使用這個注解之後,我們可以有這樣的寫法:

支援多種的輸入參數

[i]@BeforeTextChange({R.id.edit_test, R.id.helloTextView})[/i]

支援多個View綁定一個BeforeTextChange

[i]@AfterTextChange void helloTextViewAfterTextChanged(TextView edit_test)[/i]

可以在參數中指定View

[size=large][color=red][b]@EditorAction[/b][/color][/size]

這個注解是用于接收 [i]android.widget.TextView.OnEditorActionListener#onEditorAction(android.widget.TextView, int, android.view.KeyEvent)[/i] Android定義的事件。

在未使用@EditorAction 這個注解之前,我們要這麼寫代碼:

有了這個注解我們就可以這樣寫代碼了:

支援多種的輸入參數

[i]@EditorAction({R.id.edit_test, R.id.helloTextView})[/i]

支援多個View綁定一個EditorAction

[i]@EditorAction void helloTextViewEditorAction(TextView edit_test)[/i]

可以在參數中指定View

[size=large][color=red][b]@FocusChange[/b][/color][/size]

這個注解是用于接收 [i]android.view.View.OnFocusChangeListener.onFocusChange(View view, boolean hasFocus)[/i] Android定義的事件。

在沒有@FocusChange這個注解之前我們的代碼要這樣寫:

有了這個注解之後,我們的代碼可以這樣寫:

支援多種的輸入參數

[i]@FocusChange({R.id.edit_test, R.id.helloTextView})[/i]

支援多個View綁定一個EditorAction

[i]@FocusChange void helloTextViewFocusChanged(View edit_test)[/i]

可以在參數中指定View

[size=large][color=red][b]@CheckedChange[/b][/color][/size]

這個注解是用于接收 [i]android.widget.CompoundButton.OnCheckedChangeListener.onCheckedChanged(CompoundButton buttonView, boolean isChecked)[/i] Android定義的事件

在沒有@CheckedChange 這個注解這前,我們的代碼是這樣的:

在使用了這個注解之後,我們的代碼就可以這樣寫了:

支援多種的輸入參數

[i]@CheckedChange({R.id.checkboxText, R.id.helloCheckBox})[/i]

支援多個View綁定一個EditorAction

[i]@CheckedChange void helloCheckBoxCheckedChanged(CompoundButton hello)[/i]

可以在參數中指定View

[size=large][color=red][b]@Click[/b][/color][/size]

未使用@Click注解之前我們這樣寫代碼

使用後我們可以這樣寫

同樣的方法也可以處理多個View,多View的如下格式:

[size=large][color=red][b]@LongClick[/b][/color][/size]

[size=large][color=red][b]@Touch[/b][/color][/size]

[size=large][color=red][b]@ItemClick,@ItemLongClick,@ItemSelect[/b][/color][/size]

未使用注解時,我們的代碼是這個樣子地:

如果使用了了上面的注解後,代碼可以這樣寫:

[i]void listviewTest(String clickedItem)[/i]

這裡的String是Item的類型,這裡根據你的類型寫。

也可以這樣寫