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

android, android-edittext, validation

Solution

Update:

You can control the EditText to only accept numbers

<TextView 
.
.
.
android:inputType="number"
/>

or check it programmatically

In Kotlin

val number = editText123.text.toString().toIntOrNull() 
val isInteger = number != null

In Java

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");
}

Problem

Hi I'm a newbie in Android Programming. I'm trying to build an activity which includes an `edittext` field and a `button`. 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!

Original source