I have a layout which has three fields for the entry of three map coordinates. So far so good. I'm using android:inputType="numberDecimal" in the layout. When entering the field the user gets the numeric keypad. Still good.
However, when a negative coordinate needs to be entered, there is no apparent way to do this.
23.2342 works fine. 232.3421 works fine. -11.23423 can not be entered - there is no way to enter the leading negative sign, or even wrap the coordinate in ().
I'm sure I can go the route of changing this to straight text inputType, and then use a regular expression to validate that what was entered is in fact a numeric coordinate, handle error messaging back to the user, etc. But I'd rather not go that route.
I have Googled and Stackoverflowed this question for a couple hours with no luck. Any suggestions?
i m not sure about the input type but you can always create your own text filter and attach it on an editText field. that one is pretty simple. you can do the check on every character and only allow the numbers, dot or any custom character you like.
set InputType.TYPE_NUMBER_FLAG_SIGNED in
EditText.setInputType
You have to add numberSigned in the EditText tag of your layout (*.xml)
Good luck!
Unless I'm missing something this is all you need
I think that creating your own custom keylistener may be your best bet. I did something similar. I created a SignedDecimalKeyListener like this:
And then use this custom keylistener with your edittext like this:
This is working for me.
etbox.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_CLASS_NUMBER);