I want to know if it's possible to load a random picked image from an array with picasso?
This is the code i use to load my album art, but what i want to achieve is that when there is no album art found, i want to display a random image and not the same image.
private void loadAlbumArt(){
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, songList.get(songIndex).getAlbumID());
Picasso.with(getApplicationContext())
.load(albumArtUri)
.placeholder(R.drawable.no_album)
.error(R.drawable.no_album)
.noFade()
.resize(500, 0)
.into(mAlbumArt);
}
Thanks in advance,
Vince
Try this:
int[] myImageList = new int[]{R.drawable.img1, R.drawable.img2, R.drawable.img3,
R.drawable.img4, R.drawable.img5, R.drawable.img6};
Random random = new Random();
int randomNumber = random.nextInt(myImageList.length);
Picasso.with(getApplicationContext())
.load(albumArtUri)
.placeholder(R.drawable.no_album)
.error(myImageList[randomNumber])
.noFade()
.resize(500, 0)
.into(mAlbumArt);