How to open an Activity from a calculation?

Asked

Viewed 91 times

0

I am very lay in android studio and I need to do a program on an IMC calculation. The idea is simple, in the first Activity he asks for his weight and his height, after that he must do the imc (imc = weight/height²) and if the result is less than 20 he opens an Activity, if it is greater than 30 he opens another and if it is between 20 and 30 he opens a 4th Activity. Can someone help me with this function?

1 answer

1

Only use if with the account result:

    double imc = peso / Math.pow(altura,2)
if (imc <20 ){
Intent tela1 = new Intent(getApplicationContext(), tela1.class);
            startActivity(tela1);
}else if(imc > 30 ){
Intent tela2 = new Intent(getApplicationContext(), tela2.class);
            startActivity(tela2);
}else if(imc>=20 && imc <=30){
Intent tela3 = new Intent(getApplicationContext(), tela3.class);
            startActivity(tela3);
}

This inside the button click calculate. That’s the logic, I hope I’ve helped

Browser other questions tagged

You are not signed in. Login or sign up in order to post.