How to programmatically set maxLength in Android TextView?

UMAR-MOBITSOLUTIONS picture UMAR-MOBITSOLUTIONS · Mar 17, 2010 · Viewed 89.9k times · Source

I would like to programmatically set maxLength property of TextView as I don't want to hard code it in the layout. I can't see any set method related to maxLength.

Can anyone guide me how to achieve this?

Answer

Sephy picture Sephy · Mar 17, 2010

Should be something like that. but never used it for textview, only edittext :

TextView tv = new TextView(this);
int maxLength = 10;
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
tv.setFilters(fArray);