I have an edittext
in which I want only integer values to be inserted. Can somebody tell me which property I have to use?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You can use it in XML
or,
or,
Programmatically you can use
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
For example:
I need to catch pressing Enter on a keyboard with TextWatcher. But I found out that all numeric keyboards android:inputType="number" or "numberDecimal" or "numberPassword" e.t.c. don't allow me to catch Enter when user press it.
I tried
android:digits="0123456789\n"
and all numeric keyboards started to work with Enter and TextWatcher.So my way is:
plus
editText.setTransformationMethod(null)
Thanks to barmaley and abhiank.
For only digits input use
android:inputType="numberPassword"
along witheditText.setTransformationMethod(null);
to remove auto-hiding of the number.OR
android:inputType="phone"
For only digits input, I feel these couple ways are better than
android:inputType="number"
. The limitation of mentioning "number" as inputType is that the keyboard allows to switch over to characters and also lets other special characters be entered. "numberPassword" inputType doesn't have those issues as the keyboard only shows digits. Even "phone" inputType works as the keyboard doesnt allow you to switch over to characters. But you can still enter couple special characters like +, /, N, etc.android:inputType="numberPassword" with editText.setTransformationMethod(null);
inputType="phone"
inputType="number"