Based on the above image, the values of inOne=82
and inTwo=26
. Now Looking at your code, HIGH
is displayed:
if ((inOne >= 71 && inOne <= 120) && (inTwo >= 51 && inTwo <= 60))
This is not true, since your are using the &&
operator. Which means both should be in the range of high. This is the problem.
Solution: Think about how you want to deal with the situation when one of the values is in the High
range and one in the Low
range etc. etc. Then write your logic accordingly. (Example: You could also use the ||
operator, meaning if either one is 'HIGH` show high.)
Update: Here is a good source where you can read about different if/else
rules about interpreting blood pressure readings.
Update 2: I had some free time. Here is an implementation of the showText()
method based on the mentioned link:
public void ShowText() {
int inOne = sbSyst.getProgress() + 70;
int inTwo = sbDias.getProgress() + 40;
if((inOne >= 140) || (inTwo >= 90)) {
// condition 1: if 140 or more systolic or 90 or more diastolic means HIGH BP
tvRes.setText("HIGH");
tvRes.setBackgroundColor(Color.parseColor("#F70729"));
}
else if((inOne <= 90) || (inTwo <= 60)){
// (condition 1 is not met)
// condition 2: if 90 or less systolic or 60 or less diastolic means LOW BP
tvRes.setText("LOW");
tvRes.setBackgroundColor(Color.parseColor("#7659F5"));
}
else if((inOne >= 120) || (inTwo >= 80)) {
// (condition 1 and 2 are not met ==> NOT HIGH, NOT LOW)
// condition 3: if 120 or more systolic or 80 or more diastolic means PRE-HIGH BP
tvRes.setText("PRE-HIGH");
tvRes.setBackgroundColor(Color.parseColor("#D7EF0C"));
}
else if((inOne >= 90) || (inTwo >= 60)) {
// (condition 1, 2 and 3 are not met ==> NOT HIGH, NOT LOW, NOT PRE-HIGH)
// condition 4: if 90 or more systolic or 60 or more diastolic means IDEAL BP
tvRes.setText("IDEAL");
tvRes.setBackgroundColor(Color.parseColor("#0BA319"));
}
}