Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EditText edittext5 = (EditText) findViewById(R.id.edittext5);
- InputFilter[] editFilters = edittext5.getFilters();
- InputFilter[] newFilters = new InputFilter[editFilters.length + 1];
- System.arraycopy(editFilters, 0, newFilters, 0, editFilters.length);
- newFilters[editFilters.length] = new InputFilter.LengthFilter(2) {
- @Override
- public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
- if (dest.length() >= 2) {
- Toast.makeText(HomeActivity.this, "Limite de caracteres é 2", Toast.LENGTH_SHORT).show();
- return "";
- }
- return super.filter(source, start, end, dest, dstart, dend);
- }
- };
- edittext5.setFilters(newFilters);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement