トラッキング コード

9/05/2016

Android Binding AppCompatEditText: Add TextWatcher

We should implement TextWatcher interface, due to listen to change text.

public TextWatcher getEditTextWatcher() {
    return new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int count,
                int after) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
            // FIXME: when change text
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    };
}

set to app:addTextChangedListener on Layout file.

<data>
    <variable name="fragment"
              type="jp.baroqueworksdev.sample.SampleFragment"/>
</data>
<android.support.v7.AppCompatEditText
        app:addTextChangedListener="@{fragment.getEditTextWatcher}"/>

No comments:

Post a Comment