Cómo restringir el tiempo de entrada para edittext en Android

Tengo que permitir al usuario ingresar solo la hora en formato ##: ## en la edición de texto sobre la marcha, ¿hay alguna forma de lograrlo? He utilizado el código de abajo, pero no funciona.

Pude ingresar el número más de 24 valores como 45623: 5689.

edit.setInputType(InputType.TYPE_DATETIME_VARIATION_TIME)

Inclusoandroid:text="time" Tampoco está funcionando.

¿Cómo puedo lograr esto? ¿Alguien puede sugerirme cómo puedo hacer esto?

Quiero permitir que el usuario ingrese en los primeros 2 lugares hasta el valor de 23 y luego compulasary: ​​y luego el usuario puede permitir hasta el valor de 59.

por ejemplo

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

He utilizado este filtro de personalizar también, pero no funciona

Conseguí este código de algún otro lugar en SO.

Código:

    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 &= (c == ':');
            }
            if (result.length() > 3) {
                c = result.charAt(3);
                allowEdit &= (c >= '0' && c <= '5');
            }
            if (result.length() > 4) {
                c = result.charAt(4);
                allowEdit &= (c >= '0' && c <= '9');
            }
            return allowEdit ? null : "";
        }
    };

Pregunta editada: código del archivo main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="10dp" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="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_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:paddingLeft="20dp" >

            <requestFocus />
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:gravity="center"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/txtParcelDeliverTime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingRight="20dp"
            android:text="@string/delivered_time" />

        <EditText
            android:id="@+id/edTxtParcelDeliverTime"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:paddingLeft="20dp" >
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="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" />
    </LinearLayout>

</LinearLayout>

Este código funciona pero si inserto el primer alfabeto e inserto el valor correcto, entonces no funciona porquesource contiene su valor de carácter anterior.

Respuestas a la pregunta(5)

Su respuesta a la pregunta