的EditText:字符集数编程 [英] EditText : set number of characters programmatically
问题描述
我有一个的EditText
,我想限制在字符数可能在这个被输入的的EditText
,并作出这种限制的编程,该怎么办呢?例如,假设我要限制它仅允许10个字符。
I have a EditText
, and I would like to restrict the number of characters which could be inputted in this EditText
, and make this restriction programmatically, how to do it? For example, say I would like to restrict it to only allow 10 characters.
推荐答案
您可以使用输入过滤用于限制在EditView中的字符数亲语法为:
You can Use InputFilter for restricting the number of characters in EditView pro-grammatically as :
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(10);
your_edittext.setFilters(FilterArray);
有关更多帮助,你可以看到这个教程制约EditView中字符数:
for more help you can see this tutorial for restricting number of characters in EditView:
<一个href="http://www.tutorialforandroid.com/2009/02/maxlength-in-edittext-using-$c$cs.html">http://www.tutorialforandroid.com/2009/02/maxlength-in-edittext-using-$c$cs.html
这篇关于的EditText:字符集数编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!