I want to limit the text length of edit text ui element via code:
EditText et = (EditText) parent.findViewById(R.id.smsBody);;
int maxLength = 300;
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(maxLength);
et.setFilters(FilterArray);
But this gives me a null pointer exception in the last line. Any ideas whats wrong? This codes is in the onPostExecute method of my async task class. Parent is the main activity.
You should be able to put in your .xml file under your edit text:
android:maxLength=”300″
You dont need any of that other stuff in your .java file. Your .xml file controls things like color, length, size, etc.