如何在键入时测量在编辑文本中输入的字符串的长度。因为我想在输入的文本长度超过 100 个字符时显示警告。提前致谢。
问问题
2638 次
1 回答
6
您可以在 Android 中使用它来执行此操作TextWatcher
。EditText
像这样的东西
EditText test = new EditText(this);
test.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
try {
//write your code here
} catch (NumberFormatException e) {
}
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
于 2010-09-08T08:47:53.453 回答