android - How can I compare a button image to another image to see if they are equal? -


i want check if image of image button equals image. have been trying.

if(string.valueof(image1.getid()) == (selectedq.image))){                 resultalertfragment alertdialog = new resultalertfragment();                 alertdialog.show(getfragmentmanager(), "list alert");                 }                 else if(!(string.valueof(image1.getid()) == picturecorrect)){                     resultalertfragmentincorrect alertdialog = new resultalertfragmentincorrect          ();                     alertdialog.show(getfragmentmanager(), "list alert");                 } 

this image selectedq set

randomimage[] questionarray = { imageboy, imagegirl, imageman,             imagewoman, imagecow, imagedog, imagecat, imagefox };      // random int button     random randomequestion = new random(system.currenttimemillis());      int nextquestion = randomequestion.nextint((questionarray.length) - 1);     selectedq.person = questionarray[nextquestion].person;     selectedq.image = questionarray[nextquestion].image;     selectedq.displayed = questionarray[nextquestion].displayed;      // selecting random question     random randomerselection = new random(system.currenttimemillis());     int randomposition = randomerselection.nextint(3);     imageview imageposition = (imageview) findviewbyid(imageviews[randomposition]);     imageposition.setimageresource(selectedq.image);      arraylist<integer> imagesalreadyinuse = new arraylist<integer>();     (int = 0; < 4; i++) {         if (!(i == randomposition)) {             int nextimage = 0;             random randomimageforbuttons = new random(                     system.currenttimemillis());              boolean condition = false;             while (condition == false) {                 nextimage = randomimageforbuttons                         .nextint((questionarray.length) - 1);                 if (!(nextimage == nextquestion)) {                     if (!(imagesalreadyinuse                             .contains(questionarray[nextimage].image))) {                         imagesalreadyinuse                                 .add(questionarray[nextimage].image);                         condition = true;                     }                 }             }              int v = imageviews[i];             imageview iv = (imageview) findviewbyid(v);             iv.setimageresource(questionarray[nextimage].image);             questionarray[nextimage].displayed = true;         }     }      tv1.settext(selectedq.person);     picturecorrect = string.valueof(selectedq.image); 

my app asks user question. question question object has picture , string. user must select 1 picture out of 4 best suits question. these randomly generated. not sure how check if correct i.e. picture selected matches question.

can help?

you cannot track imageview's drawable resource.see this workaround can using tags

imageview0 = (imageview) findviewbyid(r.id.imageview0); imageview0.setimageresource(r.drawable.image0); imageview0.settag(r.drawable.image0);  imageview1 = (imageview) findviewbyid(r.id.imageview1); imageview0.setimageresource(r.drawable.image1); imageview1.settag(r.drawable.image1); 

then can compare tags in code like

if( view1.gettag() == view2.gettag()) {   //do } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -