I am having a editText and inputType as phone number. I would like add specific area code immediately after I enter first digit. Say for example
I enter 6 the EditText should show up +1 6.
I am trying achieve this using textWatcher but not sure how to put the number that I type after "+1"
public void afterTextChanged(Editable s)
{
if(s.length() == 1)
{
numberText.settext("+1");
numberText.setSelection(numberText.getText().length());
}
}
But the problem here is that when I enter first number the +1 is populated but the number which type through keyboard is not getting shown. I am not sure what is wrong here?
Also when I backspace and remove 1 from the text this happens but I am not able to remove + (this populates automatically). I don't want to remove +1 when I back space after +1 is populated.
Is this possible, if so how?
Thanks!
For input the next character after the +1 you should use :
For backspace the +1 you need keyListener : (not worked with soft keyboard)
EDIT
Trying to hack approach :
Replace
With
Replace
with
You are not updating the existing text properly.
Use this:
other is alright may be