EditText editText = findViewById(R.id.editText); String input = editText.getText().toString();
InputFilter[] filterArray = new InputFilter[1]; filterArray[0] = new InputFilter.LengthFilter(10); editText.setFilters(filterArray);This code sets a maximum character limit of 10 on the EditText component, preventing users from entering more than 10 characters. This is accomplished by creating an InputFilter object and passing it to the setFilters() method of the EditText component.