Android editText 输入字数限制
2010-04-21 06:53:00 来源:WEB开发网核心提示://输入框限制输入字数editText.addTextChangedListener(new TextWatcher(){private CharSequence temp;private boolean isEdit = true;@Overridepublic void afterTextChanged(Edita
//输入框限制输入字数
editText.addTextChangedListener(new TextWatcher(){
private CharSequence temp;
private boolean isEdit = true;
@Override
public void afterTextChanged(Editable s) {
if(temp.length()>Constant.TEXT_MAX){
isEdit = false;
s.delete(temp.length()-1,temp.length());
editText.setText(s);
}
}
@Override
public void beforeTextChanged(CharSequence s, int arg1,int arg2, int arg3) {
temp = s;
}
@Override
public void onTextChanged(CharSequence s, int arg1, int arg2,int arg3) {
if(isEdit == false){
Toast.makeText(KaguProductActivity.this, R.string.edit_content_limit, Toast.LENGTH_SHORT)
.show();
Editable etext = editText.getText();
int pos = etext.length();
Selection.setSelection(etext,pos);
}
}
});
[]
更多精彩
赞助商链接