Monday 22 January 2018

java - comparison of two Strings doesn't work in android

here's my code, Eclipse doesn't show any errors, program's
working fine, but it simply doesn't do exactly what i want:)



 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);

}


The application
should choose between two images to pop-up on the screen, depending on a tag stored in
the xml file.
So, if the tag says "dangerous", then should be shown the
"attention"-image.
If the tag says "not_dangerous", there should be the
"its_ok"-image.



Now, displaying the images
without an if-comparison works perfectly.



If i
print out the tags as a string, it works, it prints correctly "dangerous" or
"not_dangerous", depending on the tag.



But if
there's a if-comparison as shown above, nothing happens, no image is
shown.



Please anyone
help!!=)

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...