Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set input type to be numberdecimal but also allow a "-"

Tags:

android

I have set input type to be numberdecimal but also want to populate the editText with a "-" programmatically. I can add the text but then I am unable to edit the text as it doesn't confirm to the number decimal format. Any idea on how I can say inputtype is numberdecimal but a "-" can be allowed?

like image 577
bschandramohan Avatar asked Aug 04 '10 04:08

bschandramohan


2 Answers

I was able to achieve this behavior by setting digits xml attribute as follows:

<EditText
    ...
    android:inputType="number"
    android:digits="0123456789-"/>

Setting it up programatically (Set EditText Digits Programmatically):

weightInput.setKeyListener(DigitsKeyListener.getInstance("0123456789-"));
like image 58
7hny Avatar answered Oct 24 '22 10:10

7hny


I managed to do that with:

android:inputType="number|numberSigned"    
android:digits="0123456789-"
like image 8
RoyBS Avatar answered Oct 24 '22 08:10

RoyBS