Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mask for EditText in Android

I want to limit input in the EditText of all symbols except figures, "?" And "*". How I am able to do it?

like image 999
user725803 Avatar asked May 02 '11 08:05

user725803


1 Answers

If you also have a maximum strict length of your string, you can use a mask. I'm not sure that it's the right solution, but it's the easiest one. An easy way use a mask in your Android programs in Android Studio is to use MaskedEditText library (GitHub link).

I can not understand what does mean: figures, "?" And "", so I suppose just "?" and "". So the code is:

In your build.gradle:

compile 'ru.egslava:MaskedEditText:1.0.5'

And in your layout:

<br.com.sapereaude.maskedEditText.MaskedEditText
    android:id="@+id/phone_input"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="phone"
    android:typeface="monospace"
    mask:allowed_chars="?*"
    mask:mask="##########"
    app:keep_hint="true"
    />

This code creates an EditText that can contain ONLY "?" and "*" and max length is 10. Feel free to ask your questions :-)

like image 166
Slava Avatar answered Oct 05 '22 08:10

Slava