InputFilter w EditText powoduje powtarzanie tekstu
Próbuję zaimplementowaćEditText
Ogranicza to również wejście tylko do znaków kapitałowych [A-Z0-9] z cyframi.
Zacząłem od metody InputFilter z niektórych postów. Ale tutaj pojawia się jeden problem na Samsung Galaxy Tab 2, ale nie w emulatorze lub Nexusie 4.
Problem jest następujący:
Kiedy wpisuję „A”, tekst pokazuje „A” jego dobreTeraz, gdy wpiszę „B”, więc tekst powinien być „AB”, ale daje mi to „AAB”, co wygląda bardzo dziwnie.W skrócie powtarza znaki
Oto kod, który pracuję z tym kodem:
public class DemoFilter implements InputFilter {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
int dend) {
if (source.equals("")) { // for backspace
return source;
}
if (source.toString().matches("[a-zA-Z0-9 ]*")) // put your constraints
// here
{
return source.toString().toUpperCase();
}
return "";
}
}
Kod pliku XML:
<EditText
android:id="@+id/et_licence_plate_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="0"
android:imeOptions="actionNext"
android:inputType="textNoSuggestions"
android:maxLength="3"
android:singleLine="true"
android:textSize="18px" >
</EditText>
Całkowicie utknąłem na tym, więc każda pomoc tutaj byłaby bardzo doceniana.