Java – How do I get the integer value of the Android EditText component?

How do I get the integer value of the Android EditText component?… here is a solution to the problem.

How do I get the integer value of the Android EditText component?

I’m building an application that solves quadratic formulas based on user input from A, B, and C. I have a question. A, B, and C are all integers, but they need to take the value of an EditText component editText1 (and 2 and 3), so the formula has A, B, C to run.

How do I get the value? Here is my code, which is missing this part :

    double root1=0;
    double root2=0;
    double discriminant;
    int A;
    int B;
    int C;  
    protected void onCreate(Bundle savedInstanceState) {
         TODO Auto-generated method stub
                /** Called when the activity is first created. */
            reset button will be a menu option

final TextView textView6 = (TextView) findViewById(;
        EditText inputA = (EditText)findViewById( ;
        EditText inputB = (EditText)findViewById(;
        EditText inputC = (EditText)findViewById(; 
        Button calcbutton = (Button)findViewById(; 

calcbutton.setOnClickListener(new View.OnClickListener() { // when calculate is clicked 

public void onClick(View v) {
                 TODO Auto-generated method stub

discriminant = Math.sqrt((B*B)-(4*A*C));

                    root1 =  ((-B + discriminant)/2*A);
                    root2 =  ((-B - discriminant)/2*A);

 set textview6 to answer above    

textView6.setTag(root1 );


root1=(int) ((-B + discriminant)/2*A);

                    textView6.setText("This equation has imaginary roots");
                     equation has imaginary roots



If you read the API documentation, you’ll see that you can use the > EditText#getText() accesses the value in EditText

public void onClick(View v) {
    A = Double.parseDouble(inputA.getText().toString());
    B = Integer.parseInt(inputB.getText().toString());
    C = Integer.parseInt(inputC.getText().toString());

discriminant = Math.sqrt((B*B)-(4*A*C));

Related Problems and Solutions