Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get letter entered instantly in android?

Tags:

android

I have EditText view in android .. i want when the enters a letter the application get the letter ..

that mean the need to have a listener or event handler to get each letter is entered

hope my question is clear

like image 204
Adham Avatar asked Jan 07 '11 09:01

Adham


2 Answers

EditText et = (EditText) findViewById(R.id.EditText01);

        et.addTextChangedListener( new TextWatcher()
        {
            @Override
            public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

                try
                {
                    char currentChar = arg0.charAt(arg1); // currently typed character
                }
                catch(Exception e)
                {
                    // error
                }
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                    int arg3) {

            }

            @Override
            public void afterTextChanged(Editable arg0) {

            }
        });
like image 83
Vikas Patidar Avatar answered Sep 24 '22 11:09

Vikas Patidar


You can use the method TextView.addTextChangedListener(TextWatcher watcher)

TextWatcher provides 3 nice methods :

public abstract void afterTextChanged (Editable s)

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

public abstract void onTextChanged (CharSequence s, int start, int before, int count)

Here the doc

like image 30
Francesco Laurita Avatar answered Sep 20 '22 11:09

Francesco Laurita