mercredi 16 décembre 2015

int EditText & if/else Statement to get a string, what is wrong?

My code is about if the user entering the pH number (normal pH=7.35-7.45) it will give him the answer were is it acidic pH or alkaline pH or normal, then I want to save a string called phStatus as an answer to be called with other strings in the end in the resultTextView after the onclick method, here it is:

Button resultButton = (Button) findViewById ( R.id.resultButton ); final TextView resultTextView = (TextView) findViewById ( R.id.resultTextView );

    resultButton.setOnClickListener ( new OnClickListener ( ) {
        @Override
        public void onClick ( View v )
                        {
        EditText phET = (EditText) findViewById ( R.id.phEditText );
        int phEntered = Integer.parseInt ( phET.getText ( ).toString ( ) );
        String phStatus = "";
        if ( phEntered < 7.35 )
            {phStatus = "Acidosis";}
        else if ( phEntered > 7.45 )
            {phStatus = "Alkalosis";}
        else 
            {phStatus = "Normal acid-base balance";}


            String resultMSG = "This is " + phStatus;

                            resultTextView.setText ( resultMSG );
                        }   

Aucun commentaire:

Enregistrer un commentaire