Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enter a "Negative Decimal Number" in EditText?

I am making a calculator and I want to make sure that user is able to enter a "Negative Decimal Number" I see the option in the xml file separately for example in order to put the Decimal Number, the EditText's inputType must be numberDecimal and for negative number the inputType must be "numberSigned" but I need both. If I choose inputType as "text" then user is able to enter anything which throws an exception if it's not a number. I am not sure how to fix that either.

like image 733
ivesingh Avatar asked Jul 23 '13 13:07

ivesingh


2 Answers

You can use both with the "|" operator. Just specify "numberSigned|numberDecimal".

like image 72
André Diermann Avatar answered Oct 14 '22 02:10

André Diermann


Add this in the layout of the EditText:

android:digits="0123456789-."

You can specify more there, for example if you want the user to input sin() functions.

like image 36
g00dy Avatar answered Oct 14 '22 02:10

g00dy