Created
December 2, 2016 03:03
-
-
Save cattaka/d96b3367e9b3513c46579ce6b16eb055 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.databinding.BindingAdapter; | |
import android.text.Editable; | |
import android.text.TextWatcher; | |
import android.view.View; | |
import android.widget.TextView; | |
/** | |
* These codes are licensed under CC0. | |
* <p/> | |
* Created by cattaka on 2016/10/18. | |
*/ | |
public class TextWatcherUtils { | |
private View view; | |
@BindingAdapter("applyTextWatcher") | |
public static void applyTextWatcher(final TextView textView, final ITextWatcherListener listener) { | |
textView.addTextChangedListener(new TextWatcher() { | |
@Override | |
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { | |
listener.beforeTextChanged(textView, charSequence, i, i1, i2); | |
} | |
@Override | |
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { | |
listener.onTextChanged(textView, charSequence, i, i1, i2); | |
} | |
@Override | |
public void afterTextChanged(Editable editable) { | |
listener.afterTextChanged(textView, editable); | |
} | |
}); | |
} | |
public interface ITextWatcherListener { | |
void beforeTextChanged(TextView view, CharSequence charSequence, int i, int i1, int i2); | |
void onTextChanged(TextView view, CharSequence charSequence, int i, int i1, int i2); | |
void afterTextChanged(TextView view, Editable editable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment