How can I show the length of words typed into a textview?
This is the code, but my app stops responding if I type anything:
ed1=(EditText) findViewById(R.id.editText2);
ed1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
TextView t1=(TextView) findViewById(R.id.textView1);
t1.setText(ed1.getText().toString().length());
}
});
Code is written in onCreate().