On my android app, first time when app runs, user must type a license. The license's format is ###-XXX-###-###
where #
is a number, X
is a character. I put the format as hint but it is not sufficient. How can I make like this and user does not enter -, it just appear after 3 characters ?
UPDATE :
That's my code and it works :
licenseEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
System.out.println("afterTextChanged");
if (s.length() == 3) {
s.append("-");
}
if (s.length() == 7) {
s.append("-");
}
if (s.length() == 11) {
s.append("-");
}
if (s.length() == 15)
ok.performClick();
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
System.out.println("beforeTextChanged");
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
System.out.println("onTextChanges");
}
});
set a TextWatcher
, inside it compare intered text with a regularExpression
. and put other code like after first 3 charachets append "-" to intered characterSet .