Advertisement
Sketchware

Limita em 1 número e só aceita número 1

Jan 13th, 2023
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. EditText edittext5 = (EditText) findViewById(R.id.edittext5);
  2. InputFilter[] filters = {new InputFilter.LengthFilter(1), new InputFilter() {
  3.     @Override
  4.     public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
  5.         if (!source.toString().equals("1")) {
  6.             Toast.makeText(HomeActivity.this, "Somente o número 1 é permitido", Toast.LENGTH_SHORT).show();
  7.             return "";
  8.         }
  9.         return null;
  10.     }
  11. }};
  12. edittext5.setFilters(filters);
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement