I want to restrict the chars to 0-9, a-z, A-Z and spacebar only. Setting inputtype I can limit to digits but I cannot figure out the ways of Inputfilter looking through the docs.
相关问题
- 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
InputFilters are a little complicated in Android versions that display dictionary suggestions. You sometimes get a SpannableStringBuilder, sometimes a plain String in the
source
parameter.The following InputFilter should work. Feel free to improve this code!
It's Right, the best way to go about it to fix it in the XML Layout itself using:
as rightly pointed by Florian Fröhlich, it works well for text views even.
Just a word of caution, the characters mentioned in the
android:digits
will only be displayed, so just be careful not to miss any set of characters out :)if you want to include the white space in your input as well then add space in android:digit code as shown above.
It works fine for me even in version above android 4.0.
enjoy :)
In addition to the accepted answer, it is also possible to use e.g.:
android:inputType="textCapCharacters"
as an attribute of<EditText>
in order to only accept upper case characters (and numbers).I found this on another forum. Works like a champ.
None of posted answers did work for me. I came with my own solution: