1
任何Android專家請幫忙用輸入過濾器忽略字符-
?android忽略特殊字符輸入
我成立專班這樣做,但所有字符都被忽略.....
public class InputFilterReservedCharacters implements InputFilter {
@Override
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
try {
if (end > start) {
for (int index = start; index < end; index++) {
if (source.charAt(index) == "-".toCharArray()[0]) {
return "";
}
}
}
} catch (NumberFormatException nfe) {
}
return "";
}
}
感謝StoneBird您有幫助的評論,我想用戶除了可以輸入任何東西的「 - 」。我得到它的工作是這樣的:
@Override
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
String returnValue = "";
try {
if (end > start) {
for (int index = start; index < end; index++) {
if (source.charAt(index) != '-'){
returnValue = Character.toString(source.charAt(index));
}
}
}
} catch (NumberFormatException nfe) {
}
return returnValue;
}
通過忽略你的意思,你想從字符串中刪除' - '? – wtsang02 2013-04-23 17:19:18