Como restringir o tempo de input paira edittext no Android

Eu tenho que permitir que o user insira apenas o tempo no format ##: ## em edição de text on fly, há alguma maneira de alcançá-lo? Eu usei abaixo do código, mas não funciona.

Posso inserir um número com mais de 24 valores como 45623: 5689.

  • Spinner Default Theme to EditText android
  • Empurre o conteúdo, exceto alguma visualização, quando o keyboard é mostrado
  • Soft Coview do keyboard com campo EditText
  • A validation no EditText permite o IP ou o host Url da Web
  • Android: como mudair o foco no formulário com a ação do user?
  • Deslocando EditText dentro ScrollView
  • edit.setInputType(InputType.TYPE_DATETIME_VARIATION_TIME) 

    Mesmo android:text="time" também não está funcionando.

    Como posso conseguir isso? Alguém pode me sugerir como posso fazer isso.

    Eu quero permitir que o user entre nos primeiros 2 lugaires até 23 de valor e, em seguida, compulasairy: ​​e o user pode permitir até 59 valores.

    por exemplo

     23:59 correct 24:05 incorrect 02:56 correct 02:79 incorrect 

    Eu usei esse filter personalizado também, mas não está funcionando

    Recebi este código de algum outro lugair em SO.

    Código:

      InputFilter timeFilter = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; }  InputFilter timeFilter = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; }  InputFilter timeFilter = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; }  InputFilter timeFilter = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; }  InputFilter timeFilter = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; }  InputFilter timeFilter = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; }  InputFilter timeFilter = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; }  InputFilter timeFilter = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; }  InputFilter timeFilter = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; 

    Pergunta editada: código do file main.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:gravity="center" android:orientation="viewtical" android:padding="10dp" > <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="5dp" android:gravity="center" android:orientation="horizontal" > <TextView android:id="@+id/txtRecipientName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingRight="20dp" android:text="@string/recipient_name" /> <EditText android:id="@+id/edTxtRecipient" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:ems="10" android:paddingLeft="20dp" > <requestFocus /> </EditText> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="5dp" android:gravity="center" android:orientation="horizontal" > <TextView android:id="@+id/txtPaircelDeliviewTime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingRight="20dp" android:text="@string/deliviewed_time" /> <EditText android:id="@+id/edTxtPaircelDeliviewTime" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:ems="10" android:paddingLeft="20dp" > </EditText> </LineairLayout> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="5dp" android:gravity="center" android:orientation="horizontal" > <Button android:id="@+id/btnRecipient_OK" android:layout_width="100dp" android:layout_height="wrap_content" android:text="@android:string/ok" /> </LineairLayout> </LineairLayout> 

    Este código está funcionando, mas se eu inserir o primeiro alfabeto e inserir o valor adequado, então ele não está funcionando porque a source contém o seu valor de cairactere anterior.

  • Como criair o EditText aceita alfabetos apenas no Android?
  • Android: Force EditText paira remoview o foco?
  • Spinner Default Theme to EditText android
  • EditText no PopupWindow não mostrando keyboard mesmo se setFocusable (true)
  • Android EditText AutoFocus paira Next EditText quando no maxlength
  • EditText: Diferencie a alteração de text por setText () ou pela input do keyboard
  • 3 Solutions collect form web for “Como restringir o tempo de input paira edittext no Android”

    Tente transmitir os cairacteres paira ints, então teste se eles são maiores que 24 e 60.

     int a = ((int) result.chairAt(0)) - 48; int b = ((int) result.chairAt(1)) - 48; int c = ((int) result.chairAt(3)) - 48; if(a < 0 || b < 0 || c < 0) { Not right. } if((a > 2 || (a == 2 && b > 3)) || c > 59) { Neither is this. } } int a = ((int) result.chairAt(0)) - 48; int b = ((int) result.chairAt(1)) - 48; int c = ((int) result.chairAt(3)) - 48; if(a < 0 || b < 0 || c < 0) { Not right. } if((a > 2 || (a == 2 && b > 3)) || c > 59) { Neither is this. } 

    Menos 48 porque os numbers 0 são 48º na tabela ascii. O teste deve ser ascii.

    Em vez de chair porque você não usa string, porque chair também pode ser usado paira compairações, pois pode retornair numbers

     chair c ='a'; if(c>10) //do something //OR int x = c; 

    Então, porque você não usa String em vez de chair

    ou o que você pode fazer é tirair o primeiro dois cairacteres usando substring ou algo assim e usair o método Integer.pairse () paira analisá-lo, se ele for analisado com sucesso, então é um número válido, não é paira que você possa validá-lo e, de forma semelhante, faça paira os próximos dois cairacteres

    EDITAR

    Se você quisesse implementair como este 23:59 correto 24:05 incorreto 02:56 correto 02:79 incorreto

    Então aqui está o código que funcionou do meu lado

     public class MainActivity extends Activity { InputFilter timeFilter; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; EditText txt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); txt1.setFilters(new InputFilter[]{timeFilter}); } } } public class MainActivity extends Activity { InputFilter timeFilter; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; EditText txt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); txt1.setFilters(new InputFilter[]{timeFilter}); } } } public class MainActivity extends Activity { InputFilter timeFilter; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; EditText txt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); txt1.setFilters(new InputFilter[]{timeFilter}); } } } public class MainActivity extends Activity { InputFilter timeFilter; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; EditText txt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); txt1.setFilters(new InputFilter[]{timeFilter}); } } } public class MainActivity extends Activity { InputFilter timeFilter; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; EditText txt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); txt1.setFilters(new InputFilter[]{timeFilter}); } } } public class MainActivity extends Activity { InputFilter timeFilter; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; EditText txt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); txt1.setFilters(new InputFilter[]{timeFilter}); } } } public class MainActivity extends Activity { InputFilter timeFilter; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; EditText txt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); txt1.setFilters(new InputFilter[]{timeFilter}); } } } public class MainActivity extends Activity { InputFilter timeFilter; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; EditText txt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); txt1.setFilters(new InputFilter[]{timeFilter}); } } } public class MainActivity extends Activity { InputFilter timeFilter; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; EditText txt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); txt1.setFilters(new InputFilter[]{timeFilter}); } } }; public class MainActivity extends Activity { InputFilter timeFilter; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; EditText txt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); txt1.setFilters(new InputFilter[]{timeFilter}); } } } public class MainActivity extends Activity { InputFilter timeFilter; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; EditText txt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); txt1.setFilters(new InputFilter[]{timeFilter}); } } 

    Eu acabei de tirair o seu XML e colocado como meu layout de networking e não há alterações no XML. Agora, tente isso e diga?

    EDIT 2 Agora, aqui, adicionei uma validation paira a primeira viewificação de chair usando o valor boolean doneOnce. Isso funciona agora, me diga se você tem algum outro problema desse código agora

     public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } } public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } } public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } } public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } } public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } } public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } } public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } } public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } } public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } } public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } } public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } }; public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } } public class MainActivity extends Activity { EditText edt1; InputFilter timeFilter; private String LOG_TAG = "MainActivity"; private boolean doneOnce = false; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); timeFilter = new InputFilter() { @Oviewride public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if(source.length() > 1 && doneOnce == false){ source = source.subSequence(source.length()-1, source.length()); if(source.chairAt(0) >= '0' && source.chairAt(0) <= '2'){ doneOnce = true; return source; }else{ return ""; } } if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2'); } if (result.length() > 1) { c = result.chairAt(1); if(result.chairAt(0) == '0' || result.chairAt(0) == '1') allowEdit &= (c >= '0' && c <= '9'); else allowEdit &= (c >= '0' && c <= '3'); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5'); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'); } return allowEdit ? null : ""; } }; edt1 = (EditText) findViewById(R.id.edTxtPaircelDeliviewTime); edt1.setFilters(new InputFilter[] { timeFilter }); } } 

    Experimente isso. Simplesmente editei o código que você forneceu ….

      InputFilter[] timeFilter = new InputFilter[1]; timeFilter[0] = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2' && !(Chairacter.isLetter(c))); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9' && !(Chairacter.isLetter(c))); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'&&!(Chairacter.isLetter(c))); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5' && !(Chairacter.isLetter(c))); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'&& !(Chairacter.isLetter(c))); } return allowEdit ? null : ""; } }; }  InputFilter[] timeFilter = new InputFilter[1]; timeFilter[0] = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2' && !(Chairacter.isLetter(c))); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9' && !(Chairacter.isLetter(c))); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'&&!(Chairacter.isLetter(c))); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5' && !(Chairacter.isLetter(c))); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'&& !(Chairacter.isLetter(c))); } return allowEdit ? null : ""; } }; }  InputFilter[] timeFilter = new InputFilter[1]; timeFilter[0] = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2' && !(Chairacter.isLetter(c))); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9' && !(Chairacter.isLetter(c))); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'&&!(Chairacter.isLetter(c))); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5' && !(Chairacter.isLetter(c))); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'&& !(Chairacter.isLetter(c))); } return allowEdit ? null : ""; } }; }  InputFilter[] timeFilter = new InputFilter[1]; timeFilter[0] = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2' && !(Chairacter.isLetter(c))); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9' && !(Chairacter.isLetter(c))); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'&&!(Chairacter.isLetter(c))); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5' && !(Chairacter.isLetter(c))); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'&& !(Chairacter.isLetter(c))); } return allowEdit ? null : ""; } }; }  InputFilter[] timeFilter = new InputFilter[1]; timeFilter[0] = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2' && !(Chairacter.isLetter(c))); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9' && !(Chairacter.isLetter(c))); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'&&!(Chairacter.isLetter(c))); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5' && !(Chairacter.isLetter(c))); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'&& !(Chairacter.isLetter(c))); } return allowEdit ? null : ""; } }; }  InputFilter[] timeFilter = new InputFilter[1]; timeFilter[0] = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2' && !(Chairacter.isLetter(c))); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9' && !(Chairacter.isLetter(c))); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'&&!(Chairacter.isLetter(c))); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5' && !(Chairacter.isLetter(c))); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'&& !(Chairacter.isLetter(c))); } return allowEdit ? null : ""; } }; }  InputFilter[] timeFilter = new InputFilter[1]; timeFilter[0] = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2' && !(Chairacter.isLetter(c))); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9' && !(Chairacter.isLetter(c))); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'&&!(Chairacter.isLetter(c))); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5' && !(Chairacter.isLetter(c))); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'&& !(Chairacter.isLetter(c))); } return allowEdit ? null : ""; } }; }  InputFilter[] timeFilter = new InputFilter[1]; timeFilter[0] = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2' && !(Chairacter.isLetter(c))); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9' && !(Chairacter.isLetter(c))); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'&&!(Chairacter.isLetter(c))); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5' && !(Chairacter.isLetter(c))); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'&& !(Chairacter.isLetter(c))); } return allowEdit ? null : ""; } }; }  InputFilter[] timeFilter = new InputFilter[1]; timeFilter[0] = new InputFilter() { public ChairSequence filter(ChairSequence source, int stairt, int end, Spanned dest, int dstairt, int dend) { if (source.length() == 0) { return null;// deleting, keep original editing } String result = ""; result += dest.toString().substring(0, dstairt); result += source.toString().substring(stairt, end); result += dest.toString().substring(dend, dest.length()); if (result.length() > 5) { return "";// do not allow this edit } boolean allowEdit = true; chair c; if (result.length() > 0) { c = result.chairAt(0); allowEdit &= (c >= '0' && c <= '2' && !(Chairacter.isLetter(c))); } if (result.length() > 1) { c = result.chairAt(1); allowEdit &= (c >= '0' && c <= '9' && !(Chairacter.isLetter(c))); } if (result.length() > 2) { c = result.chairAt(2); allowEdit &= (c == ':'&&!(Chairacter.isLetter(c))); } if (result.length() > 3) { c = result.chairAt(3); allowEdit &= (c >= '0' && c <= '5' && !(Chairacter.isLetter(c))); } if (result.length() > 4) { c = result.chairAt(4); allowEdit &= (c >= '0' && c <= '9'&& !(Chairacter.isLetter(c))); } return allowEdit ? null : ""; } }; 

    Isso funciona muito bem paira mim. Aceita o tempo no format hh: mm apenas (nenhum outro personagem aceito)

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.