更改java中显示的double值的颜色
问题描述:
我想更改显示值的颜色,但是它是双精度值,我无法使用<操作数编写if条件。 显示的值是一个BAC级别,所以即使我想要,我也不能重写整个程序以获取int值。如果BAC小于0.8,则颜色应显示为绿色,如果大于0.7,则应为红色。帮帮我!更改java中显示的double值的颜色
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final);
Button backHome = (Button) findViewById(R.id.goHome);
TextView bloodAlcoholContent = (TextView) findViewById(R.id.bloodAlcoholContent);
Bundle f = getIntent().getExtras();
Bundle m = getIntent().getExtras();
final Double sendThisF = f.getDouble("actualBacF");
final Double sendThisM = m.getDouble("actualBacM");
if (m.containsKey("actualBacM")) {
String displayBac = String.format("%.2f", sendThisM);
//I would like to put if statement here but it is not allowed
if (displayBac < 0.8) {
}
}
else if (f.containsKey("actualBacF")) {
String displayBac = String.format("%.2f", sendThisF);
bloodAlcoholContent.setText(displayBac);
}
}
你应该改变你的问题标题,因为它是误导。 “更改Java中显示的双值的颜色”意味着您在更改颜色时遇到问题。事实并非如此。 – EJK
我在更改颜色时遇到问题。代码工作正常,没有我想编辑颜色 – 7kevin
@ 7kevin不,您在编写if语句来比较数字时遇到问题。如果您的问题与您的问题无关,您想做什么?这个区别很重要的原因是,其他人在比较数字时遇到问题并不会找到它,但那些具有改变颜色的实际问题的人将会得到帮助,而这两者都不会有所帮助。 –