Hello everyone, I have the following:
// recojo 2 valores del EditText
String valor1 = recullFrom.getText().toString();
String valor2 = recullTo.getText().toString();
// Transformarlos en int para usarlos
int nro1 = Integer.parseInt(valor1);
int nro2 = Integer.parseInt(valor2);
How can I verify that value1 and value2 are numbers?
I need to use them for a random and of course if I put text right now I would take it and it will hit me.
Thank you!
I recommend that in the layout of the activity you configure so that the data of that input can only be numbers.
If you don't want to do that, you can put it in a
try
to determine if it is numeric or not.A solution would be to create a method that confirms if it is of type integer or not. Here is an example:
If the method returns "true" then it is an integer data type, if it returns "false" then it is not. I hope I've helped.