【发布时间】:2011-10-12 18:33:08
【问题描述】:
这是我的代码,Eclipse 没有显示任何错误,程序运行良好,但它根本不符合我的要求:)
View image_view_danger_rate = (ImageView) findViewById(R.id.origin);
View image_view_origin = (ImageView) findViewById(R.id.danger_rate);
String entry_tag = (String) descriptionResultView.findViewById(resID).getTag();
String dangerous = "dangerous";
String not_dangerous = "not_dangerous";
if ( entry_tag == dangerous) {
image_view_danger_rate.setBackgroundResource(R.drawable.attention);
}else if ( entry_tag == not_dangerous) {
image_view_danger_rate.setBackgroundResource(R.drawable.its_ok);
image_view_origin.setBackgroundResource(R.drawable.artificial);
}
应用程序应根据 xml 文件中存储的标签在两个图像之间进行选择以在屏幕上弹出。 因此,如果标签显示“危险”,则应显示“注意”图像。 如果标签上写着“not_dangerous”,则应该有“its_ok”-图像。
现在,在没有 if 比较的情况下显示图像效果很好。
如果我将标签打印为字符串,它会起作用,它会根据标签正确打印“dangerous”或“not_dangerous”。
但如果有如上所示的 if 比较,则什么都不会发生,也不会显示图像。
请大家帮忙!!=)
【问题讨论】:
-
+1 以获得详细而完整的问题。
-
这个问题在这个网站上被问到的次数比我想找到的还要多。请使用搜索功能。
-
@Woot4Moo 重复并不一定很糟糕。 blog.stackoverflow.com/2010/11/…
-
@Woot4Moo 您指向所谓重复问题的链接甚至与此问题无关。
-
@Marcelo 甚至与本网站上关于人们不知道如何在 java 中进行字符串比较的任何其他示例有何微妙不同?