Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final EditText plateEditText = (EditText) findViewById(R.id.plate_edit_text);
- plateEditText.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 plate = s.toString();
- if (plate.length() == 7) {
- String plateFormatted = plate.substring(0, 3) + "-" + plate.substring(3, 7);
- plateEditText.setText(plateFormatted);
- plateEditText.setSelection(plateFormatted.length());
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement