用户必须输入他的手机号码,手机号码必须是10个号码,我曾经TextWatcher
这样做过,像这样
et_mobile.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
if (et_mobile.getText().toString().length() > 10) {
et_mobile.setText(et_mobile.getText().toString()
.subSequence(0, 10));
tv_mobileError.setText("Just 10 Number");
}else{
tv_mobileError.setText("*");
}
}
});
但问题是当用户输入第 11 个数字时,edittext 的光标从文本的开头开始,我希望它仍然在末尾,如何?