TextWatcher and ButterKnife library

Overview

ButterKnife library is very useful library for binding view of Android application. I will introduce the combination of TextWatcher and ButterKnife.

How to implement

@OnTextChanged(value = R.id.edit_photo_caption_row_caption,
        callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
protected void afterEditTextChanged(Editable editable) {
    // Write your code here
}

This above example shows how to implements OnTextChanged with After_Text_Changed callback.

In order to match all the methods of the TextWatcher interface, the @OnTextChanged annotation has 3 callback values.

  • The TEXT_CHANGED callback connects with the onTextChanged(CharSequence, int, int, int) method.
  • The AFTER_TEXT_CHANGED callback connects with the afterTextChanged(Editable) method.
  • The BEFORE_TEXT_CHANGED callback connects with the beforeTextChanged(CharSequence, int, int, int) method.

The default callback method for  @OnTextChanged is TEXT_CHANGED.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s