Display a random image when a button is clicked

前端 未结 4 1811
离开以前
离开以前 2021-01-23 07:59

I tried earlier and just got more confused so i will try and be more precise. I am making an app in which i have a deck of 7 cards. I want to click on the deck and have one of

4条回答
  •  鱼传尺愫
    2021-01-23 08:13

    You should be keeping the cards in an array or List of some kind. Then, you can refer to them by their number. For example:

    ArrayList deck = new ArraList();
    
    //Fill the ArrayList. Maybe shuffle it.
    
    selectedCard = ArrayList.get(randomNumber);
    

    Card could simply be String or something, instead. I don't know what sort of object you're using for it.

提交回复
热议问题