android - Set Image Resource from Enum -


i trying set image based on enum. did try research on how using post : how match int enum wasn't sure how use according code.

here's enum:

public enum imagevalue{          image1(1,r.drawable.clubs1),         image2(2,r.drawable.hearts),         image3(3,r.drawable.diamonds),         image4(4,r.drawable.spades);          private int imagevalue;         private int image;         private imagevalue(int value, int drawable){              this.imagevalue = value;             this.image = drawable;         }          public int getimagevalue(){             return image;         }      } 

this getting image values , other values:

public void newdeck() {          deck = new arraylist<card>();          (int = 0; < 13; i++) {             value = cardvalue.values()[i];              (int j = 0; j < 4; j++) {                 card = new card(value, suit.values()[j], imagevalue.values()[j] );                 this.deck.add(card);             }         }          collections.shuffle(deck);          iterator<card> carditerator = deck.iterator();          system.out.println(deck.size());          while (carditerator.hasnext()) {             acard = carditerator.next();           }         system.out.println("one card value" + "--" + acard.getcardvalue()                 + " of " + acard.getsuit()+"--"+"image value" +"----" + acard.getimagevalue());     } 

here's 1 solution post mentioned:

**coinview.setimageresource(coinarray[x].getimage());** 

now, on click of button want set random image that's being generated 1 of image views.

here:

public void onclick(view v) {            randomimage.setimageresource(**want put image here!**);       } 

i bit new enum concept , not sure how use it.

a little appreciated..thank's in advance.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -