Belgi
Belgi

Reputation: 15062

Android: How can I react when the user types inside an EditText textbox?

I have an EditText textBox and I would like to react to the user typing inside of it. Note: I want to react while the user types in the EditText so I can't have some kind of button for the user to click when he is done.

Upvotes: 3

Views: 2589

Answers (3)

DJPlayer
DJPlayer

Reputation: 3294

  editText.addTextChangedListener(new TextWatcher() { 
                        public void afterTextChanged(Editable s) { 
                                //XXX do something 
                        } 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
                                //XXX do something 
                        } 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 
                                //XXX do something 
                        } 
        }); 

Upvotes: 0

Uday
Uday

Reputation: 6023

You can use something like this (textchangelistener): If you want listen usertype on edittext

 EditText yourtext = (EditText)findViewById(R.id.medittext);
        yourtext.addTextChangedListener(new TextWatcher() {

            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

                doSomething();



            } 

        });

Hope it helps

Upvotes: 7

slund
slund

Reputation: 6397

Check out TextWatcher

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

Upvotes: 2

Related Questions