I want to restrict the user of my app entering values in an EditText. The values should look like this: 3/54/32
First number: 0..13 Middle number: 0..7 Last number: 0..255
The slashs should be shown fix in the EditText!
I already have an InputFilter for IP address but I do not understand it... ;-)
//Use a input filter for the input of the IP address
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (end > start) {
String destTxt = dest.toString();
String resultingTxt = destTxt.substring(0, dstart) + source.subSequence(start, end) + destTxt.substring(dend);
if (!resultingTxt.matches ("^\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3}(\\.(\\d{1,3})?)?)?)?)?)?")) {
return "";
} else {
String[] splits = resultingTxt.split("\\.");
for (int i=0; i<splits.length; i++) {
if (Integer.valueOf(splits[i]) > 255) {
return "";
}
}
}
}
return null;
}
};
et_router_ip.setFilters(filters);
Would be great if someone could help me!
It'S batter if you divide your Edit Text by 3 Different input view.
For that Prepare your general function in which you have to pass minimum input value , maximum input value and your Edit Text Obj Like :
Now you check current value When user typing in Edit Text using
TextWatcher
.Now same way you can call Edit_Validation(...) in your next two Edit Text Watcher.
I think it will be easy and time consuming. i also use this same approach in my one of the application.
And if you get accurate answer then share with me .