I implement some fields for input. In each of them there are hints on what text to enter. There is a field MM / YY in which the symbol "/" should be automatically substituted.
Created an adapter containing the TextWatcher interface
public void afterTextChanged(Editable s) { switch(editText.getId()) { case R.id.addcardnumber: if(editText.getText().length() == 4||editText.getText().length() == 9||editText.getText().length() == 14){ editText.setText(editText.getText()+" "); } break; case R.id.addexpdate: if(editText.getText().length() == 2){ editText.set editText.setText(editText.getText()+"/"); } break; }
Everything is working. After entering 2 characters in the MM / YY field, the “/” symbol is inserted, but the cursor flies to the beginning of the line, and the text is entered from the very beginning. Tell me how can I fix it?
And another question, you can make it so that the prompts in the input field do not disappear as soon as the field is selected, but disappear as you type.
Thank.