我想设置EditText的最大长度,但是没有成功。
我尝试过以下方法:
a.setFilters (new InputFilter[] { new InputFilter.LengthFilter (a.Length) });
我遇到了一些错误(不是在a.Length处),就像这样:
a.setMaxLength ( a.Lenght);
还有一些错误。
我认为我可能忘记了一些头文件,但这只是猜测。
提一下,我使用的是Xamarin。谢谢您的帮助。
我想设置EditText的最大长度,但是没有成功。
我尝试过以下方法:
a.setFilters (new InputFilter[] { new InputFilter.LengthFilter (a.Length) });
我遇到了一些错误(不是在a.Length处),就像这样:
a.setMaxLength ( a.Lenght);
还有一些错误。
我认为我可能忘记了一些头文件,但这只是猜测。
提一下,我使用的是Xamarin。谢谢您的帮助。
如果您正在使用C#,最好按照以下方式尝试:
MyEditText.SetFilters( new IInputFilter[] { new InputFilterLengthFilter(10) } );
请尝试
TextView a = new TextView(...);
InputFilter[] filter = new InputFilter[1];
filter[1] = new InputFilter.LengthFilter(10);
a.setFilters (filter);
android:maxLength="20"
editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(12) });
或者
EditText youredittext = new EditText(this);
int maxLength = 10;
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
youredittext.setFilters(fArray);