Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void formatInput(final String pf, final EditText et) {
- et.setText(pf);
- final TextWatcher tw = new TextWatcher() {
- String lastText = et.getText().toString();
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- String input = s.toString();
- if (TextUtils.isEmpty(input)) {
- lastText = pf;
- et.setText(pf);
- return;
- }
- if (!input.startsWith(pf)) {
- et.setText(lastText);
- return;
- }
- if (input.startsWith(pf)) {
- }
- lastText = input;
- }
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void afterTextChanged(Editable s) {
- et.setSelection(et.getText().toString().length());
- }
- };
- et.gette
- et.addTextChangedListener(tw);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement