Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final EditText phoneEditText = (EditText) findViewById(R.id.phone_edit_text);
- Button formatButton = (Button) findViewById(R.id.format_button);
- formatButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- String phoneNumber = phoneEditText.getText().toString();
- String formattedPhoneNumber = "";
- if (phoneNumber.length() == 11) {
- formattedPhoneNumber = "(" + phoneNumber.substring(0, 2) + ") " + phoneNumber.substring(2, 6) + "-" + phoneNumber.substring(6);
- } else {
- // Número de celular não está no formato correto
- }
- phoneEditText.setText(formattedPhoneNumber);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement