I am working on EdituserProfileActivity
in which I have to enter the user's height in EditText
like (5'6)(5'11)(feet'inch.) etc. Now when I enter the first character in EditText
, a single apostrophe '
is automatically added to (onTextChanged
) at the second position of EditText
.
The problem is that when I try to erase characters, it will not erase after the first position because when EditText
length is 1, it will add a '
at the second position.
How can I fix this? Please share any solutions with me.
And sorry for my bad English
edtUserHeight.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
int len=edtUserHeight.getText().toString().length();
if(len==1)
{
edtUserHeight.setText(edtUserHeight.getText()+"'");
edtUserHeight.setSelection(edtUserHeight.getText().length());
}
else{
}
}
});