Dharma Dude
Dharma Dude

Reputation: 559

Making an EditText object accept only numeric values

I'd like to create programatically an EditText within this attribute:

android:inputType="number|numberSigned|numberDecimal"

In brief I'd like it to accept only numeric values. How do I have to set my EditText object?

Upvotes: 0

Views: 894

Answers (1)

ccheneson
ccheneson

Reputation: 49410

The corresponding method for inputType is

public void setInputType (int type)

So something like the below should work (untested)

setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL )

Upvotes: 1

Related Questions