Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android EditText Set Max Length

I was trying to set the max length of an EditText, but I didn't get success.

I tried like this:

a.setFilters (new InputFilter[] { new InputFilter.LengthFilter (a.Length) });

and I get some errors ( Not at a.Length ).

and like this:

a.setMaxLength ( a.Lenght);

and still some errors.

I think that I forget some headers but that's just a guess.

Metion that I use Xamarin. Thank you in advance.

like image 488
user3836246 Avatar asked Aug 21 '14 11:08

user3836246


People also ask

How to set minimum and maximum input value in EditText in Android?

setFilters(new InputFilter[]{ new InputFilterMinMax("1", "12")}); This will allow user to enter values from 1 to 12 only.


2 Answers

If you using c# best if you try it like this

MyEditText.SetFilters( new IInputFilter[] { new InputFilterLengthFilter(10) } );
like image 116
TomerMahari Avatar answered Oct 13 '22 00:10

TomerMahari


Try

TextView a = new TextView(...);
InputFilter[] filter = new InputFilter[1];
filter[1] = new InputFilter.LengthFilter(10);
a.setFilters (filter);

or Use this in your xml:

android:maxLength="20"
like image 43
Manwal Avatar answered Oct 12 '22 22:10

Manwal