Display a random image when a button is clicked

前端 未结 4 1814
离开以前
离开以前 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:22

    Try this way

     int[] cards={R.drawable.card1,R.drawable.card2,R.drawable.card3,R.drawable.card4,R.drawable.card5,R.drawable.card6,R.drawable.card7};
     Random r = new Random();
     int n=r.nextInt(7);
     imageview.setImageResource(cards[n]);
    

提交回复
热议问题