EditText editText = findViewById(R.id.editText); editText.setFilters(new InputFilter[] {new InputFilter.LengthFilter(50)});
String maxLengthString = "This EditText view has a maximum length of 12"; EditText editText = findViewById(R.id.editText); editText.setFilters(new InputFilter[] {new InputFilter.LengthFilter(maxLengthString.length())});The EditText is a part of the android.widget package library.