Allan Macmillan
Allan Macmillan

Reputation: 1491

EditText TextWatcher not firing on removal

I have EditText with a TextWatcher that will update a TextView whenever the text is changed. However it does not fire the afterTextChanged method if i remove text from it. Why? And how can I get it to do so

    final EditText workmiles = (EditText) v.findViewById(R.id.workmiles);
    workmiles.addTextChangedListener(new TextWatcher(){

        public void afterTextChanged(Editable s) {

            int tot = GlobalSingleton.get(getActivity()).getCurrentDay().getTotalMins();

            if (!workmiles.getText().toString().equals("")){
                tot +=  Integer.parseInt(workmiles.getText().toString()) * 2;
                GlobalSingleton.get(getActivity()).getCurrentDay().setWorkmiles(Integer.parseInt(workmiles.getText().toString()));
            }

            int hours = tot / 60;
            int mins = tot % 60;
            total.setText(hours + "  hours  " + mins + "  mins");
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,int after) {}

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

Upvotes: 0

Views: 741

Answers (2)

naveed148
naveed148

Reputation: 548

Ah, I faced the same problem and figured that I was trying to debug an empty method body. Just put a statement (Log) and put a breakpoint there that was it, working.

Upvotes: 0

Vaishali Sutariya
Vaishali Sutariya

Reputation: 5121

if you feel that afterTextChanged is not fired then put Log inside this mehtod .. and if u want to get effect while text is changed in your workmiles ( EditText ) then put code inside the onTextChanged this Method

Upvotes: 1

Related Questions