Converting EditText to int? (Android)

前端 未结 11 1232
深忆病人
深忆病人 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:48

    I had the same problem myself. I'm not sure if you got it to work though, but what I had to was:

    EditText cypherInput;
    cypherInput = (EditText)findViewById(R.id.input_cipherValue);
    int cypher = Integer.parseInt(cypherInput.getText().toString());
    

    The third line of code caused the app to crash without using the .getText() before the .toString().

    Just for reference, here is my XML:

    
    

提交回复
热议问题