开发者

Numeric Soft Keyboard on Android

I am developing an开发者_如何学Python 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!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜