1

So, I want user to write two numbers divided by this symbol ":" in EditText. I've added TextWatcher to this EditText, so I can see what user is typing.

Thus, that's what I have in my Watcher in afterTextChanged.

@Override
public void afterTextChanged(Editable s) 
{
   String textToEdit = s.toString();
   if  (s.length()==2)
   {
      String h = s.toString();
      h = h+":";
      edit.setText(h);
      edit.setSelection(edit.getText().length()); 
   }

}

When user type more than 2 digits, I'm adding ":" to EditText.

And here I have problem. Input type of this EditText is "number", so, only numbers can be there and ":" is not a number.

Little example: User typed 24. afterTextChanged get it and add set "24:". 24 was a number , "24:" is a string.

So, now I have "24:" and when I try to delete something from EditText I get fatal error.

Is there any other way to show ":" in my EditText? Or what I'm doing wrong?

Aleksander Monk
  • 2,787
  • 2
  • 18
  • 31

1 Answers1

5

Try putting android:digits="0,1,2,3,4,5,6,7,8,9,:" in the xml of the EditText

*Edit: this might be android:digits="0123456789:" actually :p

Evripidis Drakos
  • 872
  • 1
  • 7
  • 15