How to programmatically set maxLength in Android TextView? How to programmatically set maxLength in Android TextView? android android

How to programmatically set maxLength in Android TextView?


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);


Try this

int maxLengthofEditText = 4;    editText.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLengthofEditText)});


Easy way limit edit text character :

EditText ed=(EditText)findViewById(R.id.edittxt);ed.setFilters(new InputFilter[]{new InputFilter.LengthFilter(15)});