Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input type for EditText in preference screen?

Tags:

Is there any way to set an EditText in my XML preference screen to only accept number input?

like image 425
Matt Avatar asked Jun 03 '11 18:06

Matt


People also ask

What is input type in EditText Android?

EditText in Android UI or applications is an input field, that is used to give input text to the application. This input text can be of multiple types like text (Characters), number (Integers), etc.

What is the EditText attribute android inputType used for?

The android:inputType attribute allows you to specify various behaviors for the input method. Most importantly, if your text field is intended for basic text input (such as for a text message), you should enable auto spelling correction with the "textAutoCorrect" value.

Why it is important that you specify the input type for each text field in your app?

Every text field expects a certain type of text input, such as an email address, phone number, or just plain text. So it's important that you specify the input type for each text field in your app so the system displays the appropriate soft input method (such as an on-screen keyboard).


2 Answers

In the xml file:

android:inputType="number"  

or during runtime:

editText.setRawInputType(TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_NORMAL); 

http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType

like image 178
Aleadam Avatar answered Sep 29 '22 04:09

Aleadam


EditTextPreference supports all the same XML attributes as does an EditText. So, use android:inputType="number"

like image 20
CommonsWare Avatar answered Sep 29 '22 02:09

CommonsWare