-1

For the if statements part, it has a red mark. and it says, operator '+' can't be applied to 'TextView', 'int'. And I have a no clue what to do with that. Am I not able to use < kind of symbol for if statement?

public class result extends AppCompatActivity {

    Button button3;
    TextView message;
    TextView SMM;
    TextView BFM;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);

        SMM     = (TextView) findViewById(R.id.SMM);
        BFM     = (TextView) findViewById(R.id.BFM);
        button3 = (Button) findViewById(R.id.button3);


        button3.setClickable(true);
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String musclemass = SMM.getText().toString();
                String fatmass    = BFM.getText().toString();

                Intent intent = new Intent();
                intent.putExtra("musclemass", musclemass);
                intent.putExtra("fatmass", fatmass);


                if(musclemass < fatmass + 50){
                    message.setText("kid");
                }

                if(musclemass > fatmass + 50){
                    message.setText("adult");
                }

            }
        });

        
    }

}

2 Answers2

0

Change

        if(SMM < BFM + 50){

to

        if(Integer.valueOf(SMM.getText().toString())< Integer.valueOf(BFM.getText().toString())+ 50){

and similar at other locations as TextView and integer are two different datatypes. You have to first get Integer value and then compare them

Naruto
  • 4,221
  • 1
  • 21
  • 32
0

Seem you don't understand what is the TextView, SMM in your case for example. You already get the string musclemass from SMM(TextView), right? How would you describe this, SMM.getText().toString ? Assume that you know you got a string. Why don't you (try to) convert this string to int (Integer). You have to screen and make sure that the input is really an Integer, not other characters. Since TextView (BFM in this case) is not an integer number, it can't be added (+) with 50.

You would better use EditText instead of TextView.

Dharman
  • 30,962
  • 25
  • 85
  • 135