I need allow to user input numeric information in a EditText, but the output needs to be formatted like "##.###,##" (# in [0..9]). The formatting I was made in a TextWatcher... this is good, the TextWatcher does the job... bute, when user selects the EditText, as it marked as text, the AlphaKeyboard is shown, if I select the EditText as numeric the keyboard I need is shown and the TextWatcher stop working.
Asked
Active
Viewed 1,592 times
4 Answers
0
put the following in your xml at the required edittext
<EditText android:inputType="number" ... />
refer to How do I show the number keyboard on an EditText in android?

Community
- 1
- 1

Amol Gupta
- 704
- 1
- 8
- 26
0
You need to change edittext entry like this.
<EditText android:inputType="phone" android:numeric="decimal"></EditText>

kosa
- 65,990
- 13
- 130
- 167
0
Use this code to show soft keypad.
InputMethodManager imm = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInputFromInputMethod(v.getApplicationWindowToken(), 1);

picaso
- 713
- 2
- 14
- 26
0
As you are doing formatting in TextWatcher (##,####....) i.e. you are adding "," in EditText and you have made the EditText as numeric. If its numeric then "," char is invalid. Thus its not allowing TextWatcher to update the formatted text that contains ',".
You have 3 options to deal with this problem :
- Make the EditText as normal instead of numeric. In TextWatcher look out for any other invalid chars other than 0-9. You can show IME for Mumber keypad when the focus is on the EditText.
- Use Mask for EditText.
- Let it be numeric. Trap FocusGain & FocusLost for the EditText. In focusGain, remove the formatting & set the inputType to Numeric. & In focusLost, first make the input type to Normal and then update the entered value to formmated value. You can set the input type to normal at runtime using
setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL);
& for numeric use :setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
I believe 1st option will be best to handle and manage out.

Tvd
- 4,463
- 18
- 79
- 125
-
Hi @Tvd, thanks for your reply, I did the first suggestions, as I describe in my question, but I don't try change InputType when EditText gets the focus... Can You explain about MASK ? – nonickh Feb 03 '12 at 19:45
-
@nonickh, For Mask, you cna use InputFilter - How to use : http://itdumka.com.ua/index.php?cmd=shownode&node=32 InputFilter -http://developer.android.com/reference/android/text/InputFilter.html. – Tvd Feb 04 '12 at 14:21