Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- edtPhone.addTextChangedListener(new TextWatcher() {
- @Override
- public void afterTextChanged(Editable s) {
- String phone = s.toString();
- if (phone.length() == 12) {
- String formattedPhone = String.format("(%s) %s-%s",
- phone.substring(0, 2),
- phone.substring(2, 6),
- phone.substring(6, 10));
- edtPhone.setText(formattedPhone);
- }
- }
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {}
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement