Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I call a function as I type in an Android EditText [closed]

Here's my scenario. I want to integrate into an EditText a search function. But I don't want it to be an external button, I want to call that function as I type in the EditBox.

How can I achieve this ? Thank you.

like image 850
Phantom Avatar asked Dec 15 '22 15:12

Phantom


1 Answers

You need a TextWatcher for your EditText. The three callbacks are called when the text, in the attached EditText changes

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

        }

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

            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {

            // TODO Auto-generated method stub
        }
    });

you can find more details on the documentation, here

like image 51
Blackbelt Avatar answered Dec 17 '22 04:12

Blackbelt