Answer the question
In order to leave comments, you need to log in
How to perform validation in EditText in Android?
Hello! My task is to develop an EditText view into which we enter a phone. In Edit Text, we see a hint like this: +7(___)___-__-__ The user starts typing numbers right after 7, and as characters are typed, underscores remain. I don't know where to start solving this problem, and I need a hint in which direction I need to go. Perhaps you have a ready-made solution and please share it)
Answer the question
In order to leave comments, you need to log in
There is a good solution: https://github.com/RedMadRobot/input-mask-android . But if you really want to do it yourself - look towards InputFilters
This is done using the TextWatcher listener:
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question