开发者

Is there a way to fire an event when the contents of an EditText view have changed?

开发者 https://www.devze.com 2022-12-14 12:44 出处:网络
I can see keys on the device fire for a particular View with onKey, but this doesn\'t fire when keys on the开发者_运维问答 software keyboard are pressed.

I can see keys on the device fire for a particular View with onKey, but this doesn't fire when keys on the开发者_运维问答 software keyboard are pressed.

I am trying to build a dynamic UI that recalculates a value as the input changes, while it's changing.

Is there a way to capture either that the value of the EditText has changed?


Yeah, you just need to add a TextChangedListener:

textEdit.addTextChangedListener(new TextWatcher(){

        @Override
        public void afterTextChanged(Editable editable)
        {
            // Do Stuff

        }

        @Override
        public void beforeTextChanged(CharSequence text, int start, int count, int after)
        {
            // Do Stuff

        }

        @Override
        public void onTextChanged(CharSequence arg0, int start, int before, int count)
        {
            // Do Stuff

        }

    });

You can find more info here:
https://developer.android.com/reference/android/text/TextWatcher.html


Per: http://developer.android.com/reference/android/text/TextWatcher.html

    editText.addTextChangedListener(new TextWatcher() {
        public void onTextChanged (CharSequence s, int start, int before, int count) {

        }
        public void afterTextChanged (Editable s) {

        }
        public void beforeTextChanged (CharSequence s, int start, int count, int after) {

        }
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消