Here is the code I'm trying :
public void onTextChanged(CharSequence s, int start, int before, int count) {
try {
String strEnteredVal = edtMaxAge.getText().toString();
if(!strEnteredVal.equals("")) {
int num = Integer.parseInt(strEnteredVal);
if (num < 125) {
edtMaxAge.setText(num);
} else {
Toast.makeText(getContext(), "max age should be less than 125 ", Toast.LENGTH_SHORT).show();
edtMaxAge.setText("");
}
}
} catch (NumberFormatException ex) {
// Do something
}
}
When I enter a number >= 125 I need to show a popup message, like "max age should be less than 125", without accepting the characters.