Boardy
Boardy

Reputation: 36205

EditText input numbers as password style on Android

I am currently developing an App for Android. I am creating an Alert Dialog with input boxes and I need the input boxes to be numbers only but as a password input. How can I do this google isn't finding me anything only one or the other. This needs to be done programatically not using XML

Upvotes: 1

Views: 3488

Answers (3)

Reed
Reed

Reputation: 14974

In your xml

<EditText
android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:password="true"
android:digits="1234567890" 
android:inputType="number"/>

the digits part makes it so you can't use symbols or any other characters, and this ensures that ONLY numbers will be entered. using the inputType="phone" method, parentheses and pound signs can still be entered

Upvotes: 1

LTEHUB
LTEHUB

Reputation: 1648

Edittext set for password with phone number input? (android)

<EditText
android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:password="true"
android:inputType="phone" />

Upvotes: 3

ccheneson
ccheneson

Reputation: 49410

Set the input type of your Edittext with setInputType(TYPE_NUMBER_VARIATION_PASSWORD). More info here. It seems it's only available from Honeycomb

Upvotes: 1

Related Questions