0

I am using the TextWatcher() method to listen on my EditText. It has a method called afterTextChanged(Editable s) I want to display a Toast saying "Changes saved" in this method.

For the Toast.makeText(Context context, "message", Toast.LENGTH_SHORT).show();

What context I should pass in ??. I have already tried this and "name_of_Fragment.this" but it wont work.

Anybody knows what to do ??

 mTitleField.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            //Nothing to do!!
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //save the text and overwrite
            mCrime.setTitle(s.toString());

        }

        @Override
        public void afterTextChanged(Editable s) {
            // I want the Toast here!!


        }
    });
    return v;
}
2
  • 2
    If u r trying this in fragment use getActivity(). Commented Jul 12, 2016 at 10:10
  • Probably TextChangedListner may get hanged if you do continuous text changes. Commented Jul 12, 2016 at 10:17

1 Answer 1

0

Try with,

getActivity();

this may helps you

Sign up to request clarification or add additional context in comments.

2 Comments

that won't work, inside of the TextWatcher object this refers to the TextWatcher. You probably meant name_of_Fragment.this.getActivity() as mentioned above
yeah, right. @ MidasLefko . see my edited answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.