I have to allow user to input only time in ##:## format in edit text on the fly, is there any way to achieve it? I have used below code but it doest not working.
I able to enter number more than 24 value like 45623:5689.
edit.setInputType(InputType.TYPE_DATETIME_VARIATION_TIME)
Even android:text="time" is also not working.
how can i achieve this thing. Can anybody suggest me how can i do this thing.
I want to allow user to enter in first 2 places up to 23 value and then compulasary : and then user can allow up to 59 value.
for example
23:59 correct
24:05 incorrect
02:56 correct
02:79 incorrect
I used this customize filter also but its not working
I got this code from some where else in SO.
Code:
InputFilter timeFilter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
int dstart, int dend) {
if (source.length() == 0) {
return null;// deleting, keep original editing
}
String result = "";
result += dest.toString().substring(0, dstart);
result += source.toString().substring(start, end);
result += dest.toString().substring(dend, dest.length());
if (result.length() > 5) {
return "";// do not allow this edit
}
boolean allowEdit = true;
char c;
if (result.length() > 0) {
c = result.charAt(0);
allowEdit &= (c >= '0' && c <= '2');
}
if (result.length() > 1) {
c = result.charAt(1);
allowEdit &= (c >= '0' && c <= '9');
}
if (result.length() > 2) {
c = result.charAt(2);
allowEdit &