Numeric Soft Keyboard on Android - android

I am developing an android application where we are using WebView to display Web page being served from Web Server. Everything is working fine except with the problem that when i am using the soft keyboard and switched to numeric key entry and move from first field to next field, the keyboard layout automatically changed to alphanumeric.
Is there any way using which i can pull up virtual keyboard in numeric mode only when i need to enter numbers only?
Thanks and Regards.

editTextField.setRawInputType(Configuration.KEYBOARD_QWERTY);
This shows the normal key pad with the numeric version first, yet allows you to switch between them.
getInput.setRawInputType(Configuration.KEYBOARD_12KEY);
This shows numeric only, with no option to enter text values.
I ran into a similar situation. I wanted numeric values only, but I have a "hint" that was text. Setting the inputType to number would not allow the hint to be displayed. This works around it fine.

Configuration.KEYBOARD_12KEY or Configuration.KEYBOARD_QWERTY is wrong way.
You have to use InputType (show doc here) on the EditText setRawInputType().

If you are talking about HTML, you could use HTML5 features, for example:
Number: <input type="number" name="points" min="1" max="10" />
Have tested this in HTC Desire browser, and it brings up different (numeric) keyboard when you enter data into such field.

Is there any way using which i can
pull up virtual keyboard in numeric
mode only when i need to enter numbers
only?
Yes, you can specify android:inputType XML attribute with the number or numberDecimal value:
<EditText
android:text=""
android:id="#+id/editTextNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal">
</EditText>
Enjoy!!

Related

android inputType="number" and "numberPassword" different keyboards, how to make same keyboards?

When in EditText xml layout I set android:inputType="number" I see one keyboard, with dash, dot and comma.
When I set android:inputType="numberPassword" I see another keyboard, only numbers this time.
How do I show keyboard with only numbers, without dot and comma, for a non-password EditText?
if you need only numbers then best option for you would be android:inputType="numberSigned"
and the keyboard... well, in fact keyboard style doesn't depend on you... this is another separated app installed in system and it try to fit inputType of EditText. some keyboard apps may have different buttons for inputType="number" and inputType="numberPassword", some other may have same UI, yet some other may just have one UI with all buttons for all inputTypes (thus some of these buttons may be inactive, e.g. letters when digit-only inputType)
even when your keyboard app provides different keyboard style doesn't mean that on another device with another keyboard app this behavior will be the same
you can join 2 types in inputType EditText in android
this link all type for EditText
for example you can use :
android:inputType="numberSigned|numberDecimal"
or
android:inputType="numberDecimal"

Digit keyboard by default but allowing alphabetic characters

I have an EditText box and I want the default keyboard that comes up when it is selected to be the numeric keypad. However, I do want to allow users to enter alphabetic characters too. The solutions android:inputType="number" , et.setRawInputType(InputType.TYPE_CLASS_NUMBER)...etc does not work for me because restricts input to numeric digits only. Does someone know some solution??
Add the following line of code, and it will do the trick :)
editText.setRawInputType(Configuration.KEYBOARD_QWERTY);
This will show the the numeric keypad first, but also allows you to enter free text.
More information tap here
This problem is similar to the this.

lock android keyboard to only show numerics

I have an android app that uses an EditText with android:inputType="number"
when the edittext first displays the softkeyboard appears with only numerics enabled (you can still see the other keys though.
The EditText also has android:digits="0123456789\n" as I want the users to be able to enter multiple lines
As soon as I hit the ENTER key to create another line the numeric keys disappear.
How can I...
a). Only show a numeric keyboard (with Enter key) e.g. just 0123456789?
b). Stop the softkeyboard showing all the other keys?
You want a multiline EditText and numeric keyboard? Seems possible, but deprecated. Check out this answer.
Update:
If everything fails, try to enforce the numeric type every time a line break is inserted:
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
Found a solution
by employing
android:digits="0123456789\n"
android:inputType="phone|textMultiLine"
I obtain the desired effect.
Try this
editTextField.setRawInputType(Configuration.KEYBOARD_QWERTY);
This shows the normal key pad with the numeric version first, yet allows you to switch between them.
getInput.setRawInputType(Configuration.KEYBOARD_12KEY);

Android - Using same keyboard, as the browser adress bar, in a EditText

I wanted the keyboard that android have with the shortcuts to ".com" to an editText, and another for an email input with the "#".
I've tried different things like this:
email_edit.setRawInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
facebook_edit.setRawInputType(InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT);
twitter_edit.setRawInputType(InputType.TYPE_TEXT_VARIATION_URI);
but nothing works and the keyboard that appears is the normal one.
Any suggestions?
Thanks!
On your EditText you can set the input type:
android:inputType="textEmailAddress"
In code you can use:
editText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);

How do I default to numeric keyboard on EditText without forcing numeric input? [duplicate]

This question already has answers here:
EditText with number keypad by default, but allowing alphabetic characters
(19 answers)
Closed 9 years ago.
This has been asked elsewhere online to no avail. Is there any way in Android to display the numeric soft keyboard when focusing on an EditText, but still allow any text to be entered?
I'd like to let the user enter quantities (e.g. "1 kg", "2 L"), so just setting inputType="number" won't work.
Add the following line of code, and it will do the trick :)
editText.setRawInputType(Configuration.KEYBOARD_QWERTY);
This will show the the numeric keypad first, but also allows you to enter free text.
More information here.
This may be device dependant but have you tried:
android:inputType="phone"
All Input Types Link
in the EditText's xml , this gives you the number pad keyboard but then you can still switch to letter's if you want. (Atleast on my Nexus One).
Note that: setRawInputType(InputType.TYPE_CLASS_NUMBER);
has the desired effect on some devices but not others...
On htc it works fine however on galaxy tab II you only get the numeric keyboard and no way to switch back to alpha.
write the code in XML,
android:numeric="integer"
android:inputType="phone"
android:digits="1234567890"
It looks like the underlying question you're dealing with is: how can I allow the user to enter quantities?
One appropriate answer is: with a numeric input, paired with some form of category select for the unit. e.g. radio, dropdown, or spinner. This is probably easier to use and also saves you the headache of having to validate your input every time.
You could also just have iron cojones and write a custom soft keyboard.
I tried many different combinations before I figured this out, but this appears to work correctly:
setRawInputType(InputType.TYPE_CLASS_NUMBER);
The key lies in the description for setRawInputType(int):
Directly change the content type integer of the text view, without
modifying any other state.

Categories

Resources