Search code examples
javaandroidandroid-layoutsettextr.java-file

Making math operations in setText?


Why I'm getting error on this line ?

textView1.setText((editText1.getText() + editText2.getText() + (editText3.getText)) / 3);

Can we do math operations in setText method ?


Solution

  • Try this :

    float result = (Integer.parseInt(editText1.getText().toString()) +Integer.parseInt(editText2.getText().toString())+Integer.parseInt(editText3.getText().toString()))/ 3;
    textView1.setText(""+result );