pouria pouria - 6 months ago 21
Android Question

afterTextChange in TextWatcher how handel backspace and setText("")?

I have an

EditText
and I use
afterTextChange()
to get values for every character, character by character. Well I have a button to do editText.setText("") but when I use that I get this error charAt: 0 >= length 0.

How can I handle this error and how can I handle backspace?


My code is :


@Override
public void afterTextChanged(Editable s) {


enigmaCoding(String.valueOf(s.charAt(ii)));
ii++;

}

});


public void restart(View view) {

ii = 0;
txtV.setText("");
etxtC.setText("");

N J N J
Answer

You can check

if(s!=null && s.toString().length()>0)
{
  enigmaCoding(String.valueOf(s.charAt(ii)));
  ii++;
}
Comments