Please someone can explain to me the purpose of the source and dest parameters in android.text.InputFilter#filter
?
I tried to read the docs but I am really confused. I am trying to use a regex to make an IP mask. Any help is appreciated.
I get it now. So, for example, if I have 123.42, then the user types 123.42d, I will have:
dest = 123.42
source = 123.42d
start = 5
end = 6
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter()
{
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
String destTxt = dest.toString();
String resultingTxt = destTxt.substring(0, dstart) + source.subSequence(start, end) + destTxt.substring(dend);
if(resultingTxt.equals("")) return "";
int lastChar = resultingTxt.length() -1;
if(String.valueOf(resultingTxt.charAt(lastChar)).matches("[^0-9.]"))
{
return "";
}
return null;
}
};
This isn't working though. Shouldn't this return me only the digits? It happens that depending on what the user type it returns me characters too.