Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get random images in Android Studio

I am trying to create a card game for an android app (for practice) and I was wondering how would I upload random cards into the players hand? I have the GUI implemented and I think I would need something along the lines of a typedarray and

   ((ImageView)findViewById(R.id.textView18)).setImageResource(R.drawable.1c);

Am I moving along the right tracks with this?

like image 618
DataStructors23 Avatar asked Dec 14 '22 03:12

DataStructors23


1 Answers

You can get random images like this:

int[] images = {R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4};
Random rand = new Random();
imageView.setImageResource(images[rand.nextInt(images.length)]);
like image 66
SpiralDev Avatar answered Dec 23 '22 08:12

SpiralDev