Issue
This Content is from Stack Overflow. Question asked by Nikki
The requirements have the two first fun to be in ViewModel. val f and run are in Main Activity. The loop is stopping. I think there might be an issue toFloat(). Is there something that I am missing? Thank you for the help.
val f = bmiViewModel.updatebmi(bmiViewModel.formula(inc, wt, ft))
run(f)
fun formula(inc: Int, ft: Int, wt: Int): Float {
val htTotal = (ft*12).toFloat() + inc.toFloat()
val BMI = (wt.toFloat()*703) / (htTotal * htTotal)
Log.d(TAG,"BMI", Exception())
return BMI
fun updatebmi(total: Float): Int{
if (total < 18.5) {
return -256
} else if (total >= 18.5 && total < 24.9) {
return 8
} else if (total >= 24.9 && total < 30) {
return 256
} else{
return 16
}
}
private fun run(i: Int){
if (i == -256) {
binding.status.text = "Under Weight"
binding.status.setTextColor(i)
} else if (i == 8) {
binding.status.text = "Normal"
binding.status.setTextColor(i)
} else if (i == 256) {
binding.status.text = "Overweight"
binding.status.setTextColor(-256)
} else{
binding.status.text = "Obese"
binding.status.setTextColor(16)
}
Solution
This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.
This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.