Converting EditText to int? (Android)

前端 未结 11 1237
深忆病人
深忆病人 2020-12-09 03:08

I am wondering how to convert an edittext input to an int, I have the user input a number, it than divides it by 8.

MainActivity.java

@SuppressWarnin         


        
11条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 03:51

    First, find your EditText in the resource of the android studio by using this code:

    EditText value = (EditText) findViewById(R.id.editText1);

    Then convert EditText value into a string and then parse the value to an int.

    int number = Integer.parseInt(x.getText().toString());

    This will work

提交回复
热议问题