Ich habe versucht, den ganzen Tag herauszufinden, wie ich ein Bild je nach dem Ergebnis der Berechnung hinzufügen möchte. Ich erstelle einen BMI-Rechner. Ich habe es perfekt im Android Studio funktioniert. Möchte nur ein dünnes Bild hinzufügen, wenn ein Ergebnis ein dünnes oder dickes Bild ist, wenn es Übergewicht sagt. Hier ist der Code. Danke.Hinzufügen eines Bildes in Abhängigkeit von der Berechnung
package ie.wit.fitnessmadeeasy;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class BmiActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bmi);
final Button calc = (Button) findViewById(R.id.calc);
final EditText weight = (EditText) findViewById(R.id.weight);
final EditText height = (EditText) findViewById(R.id.height);
final TextView result = (TextView) findViewById(R.id.result);
calc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String heightStr = height.getText().toString();
String weightStr = weight.getText().toString();
if (heightStr != null && !"".equals(heightStr)
&& weightStr != null && !"".equals(weightStr)) {
float heightValue = Float.parseFloat(heightStr)/100;
float weightValue = Float.parseFloat(weightStr);
float bmi = weightValue/(heightValue * heightValue);
String bmiLabel = "";
if (bmi <= 15) {
bmiLabel = getString(R.string.very_very_skinny);
} else if (bmi > 15 && bmi <= 16) {
bmiLabel = getString(R.string.very_skinny);
} else if (bmi > 15 && bmi <= 18.5) {
bmiLabel = getString(R.string.skinny);
} else if (bmi > 18.5 && bmi <= 25) {
bmiLabel = getString(R.string.normal);
} else if (bmi > 25 && bmi <= 30) {
bmiLabel = getString(R.string.overweight);
} else if (bmi > 30 && bmi <= 35) {
bmiLabel = getString(R.string.obese_series_i);
} else if (bmi > 35 && bmi <= 40) {
bmiLabel = getString(R.string.obese_series_ii);
} else {
bmiLabel = getString(R.string.obese_series_iii);
}
bmiLabel = bmi + "\n\n" + bmiLabel;
result.setText(bmiLabel);
}
}
});
}
}
Erkläre dein Problem, was hast du versucht und was nicht? –