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() == 8) {
- Toast.makeText(getApplicationContext(), "Plate number has reached 8 characters!", Toast.LENGTH_SHORT).show();
- }
- if (plate.length() > 8) {
- s.delete(8, s.length());
- }
- if (plate.length() == 7) {
- final 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