add a listener in editText [duplicate]

-2

As I do to make an action to be executed, every time the user type some letter in the editText, I searched but did not find what I wanted, if anyone knows at least one hint how to search already help

    
asked by anonymous 30.03.2017 / 17:18

1 answer

1

In your EditText you add the addTextChangedListener() method as follows:

package genesysgeneration.svg;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        EditText editText = (EditText)findViewById(R.id.editText);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                
                //aqui você executa uma determinada ação antes da modificação do editText
                
            }

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

                //aqui você executa uma determinada ação durante a modificação do editText

            }

            @Override
            public void afterTextChanged(Editable s) {

                //aqui você executa uma determinada ação depois da modificação do editText

            }
        });

    }
}

In it you have 3 options for executing an action, before edtText is modified, during and after. You choose one of the three according to your need.

    
30.03.2017 / 23:03