尝试使用InputFilter作为:
InputFilter[] digitsfilters = new InputFilter[1];
digitsfilters[0] = new InputFilter(){
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
// TODO Auto-generated method stub
if (end > start) {
char[] acceptedChars = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
for (int index = start; index < end; index++) {
if (!new String(acceptedChars).contains(String.valueOf(source.charAt(index)))) {
return "";
}
}
}
return null;
}
};
manual_ip= (EditText)findViewById(R.id.manual_ip);
manual_ip.setFilters(digitsfilters);