Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final EditText cpfEditText = (EditText) findViewById(R.id.cpf_edit_text);
- cpfEditText.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
- @Override
- public void afterTextChanged(Editable s) {
- final String cpf = s.toString();
- if (cpf.length() == 11) {
- String cpfFormatado = cpf.substring(0, 3) + "." + cpf.substring(3, 6) + "." + cpf.substring(6, 9) + "-" + cpf.substring(9, 11);
- cpfEditText.setText(cpfFormatado);
- cpfEditText.setSelection(cpfFormatado.length());
- }
- }
- });
Add Comment
Please, Sign In to add comment