I'd like to change the string to an integer. There's edittext, and the user enters a number here. I received it as String hello, but I want to change it to Integer instead of String.
EditText et = (EditText) findViewById(R.id.entry1);
String hello = et.getText().toString();
By the way, how do I get the value of EditText as an Integer?
android-edittext string android java integer
Integer.parseInt(et.getText().toString());
You can do it like this.
int myNum = 0;
try {
myNum = Integer.parseInt(et.getText().toString());
} } catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
I think it would be good to make an exception just in case.
© 2024 OneMinuteCode. All rights reserved.