Call TextWatcher method

0

Good afternoon! I'm starting Java studies and I came to this topic. How do I call the insert method on the side of Activity , passing the EditText required field?

public static TextWatcher insert(final EditText editText){
    return new TextWatcher() {
    ...
    public void onTextChanged(CharSequence cs, int start, int before, int count){
        editText.setText("Qualquer coisa");
    
asked by anonymous 14.12.2017 / 16:42

2 answers

0

Since your method is static you will need to reference Activity

Example

EditText myEditText = (EditText) findViewById(R.id.edit_text);
MyActivity.insert(myEditText);

I hope it helps!

    
14.12.2017 / 17:12
0

In the Activity where reporting is initialized you can add the textWatcher to the edit to receive a message when the editText is changed, like this:

        reportar=(TextView)findViewById(R.id.txtReport);        
        reportar.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

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

        @Override
        public void afterTextChanged(Editable s) {
         /* insira código que o ocorre quando edit reportar for alterado.
menos mudar o próprio edit reportar. */



        }
    });
    
14.12.2017 / 17:35