我是Android的初學者。 我有一個字母的EditText。它只接受字符。當用戶在鍵盤上輸入不同的字符時,我需要用新的字符替換輸入的字符。我怎樣才能達到目的?這可能嗎?Android EditText
// Set edit text width only to one character
InputFilter[] FilterArray = new InputFilter[2];
FilterArray[0] = new InputFilter.LengthFilter(1);
FilterArray[1] = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
if (!Character.isLetter(source.charAt(i))
&& !Character.isSpaceChar(source.charAt(i))) {
return "";
}
}
return null;
}
};
editLetter.setFilters(FilterArray);
謝謝
Igor
2011-04-05 14:20:54