Advertisement
Sketchware

Formatação de placa

Jan 13th, 2023
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. final EditText plateEditText = (EditText) findViewById(R.id.plate_edit_text);
  2. plateEditText.addTextChangedListener(new TextWatcher() {
  3.     @Override
  4.     public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  5.     }
  6.     @Override
  7.     public void onTextChanged(CharSequence s, int start, int before, int count) {
  8.     }
  9.     @Override
  10.     public void afterTextChanged(Editable s) {
  11.         final String plate = s.toString();
  12.         if (plate.length() == 7) {
  13.             String plateFormatted = plate.substring(0, 3) + "-" + plate.substring(3, 7);
  14.             plateEditText.setText(plateFormatted);
  15.             plateEditText.setSelection(plateFormatted.length());
  16.         }
  17.     }
  18. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement