这是我的代码,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);
}
Run Code Online (Sandbox Code Playgroud)
应用程序应在屏幕上弹出两个图像,具体取决于存储在xml文件中的标记.因此,如果标签显示"危险",那么应该显示"注意" - 图像.如果标签显示"not_dangerous",则应该有"its_ok"-image.
现在,在没有if-comparison的情况下显示图像非常有效.
如果我将标签打印为字符串,它可以正常打印,它会正确打印"危险"或"非危险",具体取决于标签.
但如果有如上所示的if-comparison,则没有任何反应,也没有显示图像.
请任何人帮忙!! =)