Advertisement
Sketchware

Formatação para celular

Jan 21st, 2023
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. edtPhone.addTextChangedListener(new TextWatcher() {
  2.   @Override
  3.   public void afterTextChanged(Editable s) {
  4.     String phone = s.toString();
  5.     if (phone.length() == 12) {
  6.       String formattedPhone = String.format("(%s) %s-%s",
  7.       phone.substring(0, 2),
  8.       phone.substring(2, 6),
  9.       phone.substring(6, 10));
  10.       edtPhone.setText(formattedPhone);
  11.     }
  12.   }
  13.   @Override
  14.   public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
  15.   @Override
  16.   public void onTextChanged(CharSequence s, int start, int before, int count) {}
  17. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement