0
homeworkText = (EditText) getActivity().findViewById(R.id.homeworkText);

homeworkText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(300)});

In this code I wanna limited count of input chars. But when I paste to field text over limit (for example, in field has 200 chars and I paste text with 150 chars) app just finish without errors in run-console

How make safe limit to inputed chars?

1 Answers1

0
 homeworkText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.length() > 300) {
                    homeworkText.setText(s.toString().substring(0, 300));
                }
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

My question solved like this

And I removed InputFilter