Converting EditText to int? (Android) Converting EditText to int? (Android) android android

Converting EditText to int? (Android)


you have to used.

String value= et.getText().toString();int finalValue=Integer.parseInt(value);

if you have only allow enter number then set EditText property.

android:inputType="number"

if this is helpful then accept otherwise put your comment.


Use Integer.parseInt, and make sure you catch the NumberFormatException that it throws if the input is not an integer.


I'm very sleepy and tired right now but wouldn't this work?:

EditText et = (EditText)findViewById(R.id.editText1);String sTextFromET = et.getText().toString();int nIntFromET = new Integer(sTextFromET).intValue();

OR

try{    int nIntFromET = Integer.parseInt(sTextFromET);}catch (NumberFormatException e){    // handle the exception}