Yansuck Yansuck - 1 year ago 77
Android Question

How to determine if an input in EditText is an integer?

Hi I am a newbie in Android Programming.

I am trying to build an activity which includes an edittext field and a buttom. When user type in an integer, the button will lead them to the next activity. However I do not if there's a way to check the type of user's input.

Anyone can help me? Thank you very much!

Answer Source
String text = editText123.getText().toString();
try {
   int num = Integer.parseInt(text);
   Log.i("",num+" is a number");
} catch (NumberFormatException e) {
   Log.i("",text+" is not a number");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download