I have an EditText having a maximum supporting character of 10. What i want is when i type the count should decrement and on backspace the count should increment.....
private static TextView messageCount=null;
messageCount=(TextView) findViewById(R.id.messageCount);
mMessageField.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
if(count>0)
{
count--;
messageCount.setText("Count=>"+count);
//Toast.makeText(mContext, "Count=>"+count, Toast.LENGTH_LONG).show();
}
}
});
Try something like this:
it will tell you length of textview. Put this inside "onTextChanged" so by doing so length will increase or decrease according to text you enter or delete.