Randomize Images
Randomize Images
ID: img2
ID: img3
ID: img4
ID: btnNext
Every time you tap on button NEXT, the images in the four boxes
will be randomized and covered with question mark.
package com.example.randomize_images;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
//this will loop 16 times, and everytime it loops the number stored in arr variable
using the arr.add
for (int i = 1; i <= 16; ++i) arr.add(i);
btnNext.setOnClickListener(v -> {
getRandomNumber();
});
imgOne.setOnClickListener(v -> {
//call flipImageBox and provide the number of the image button being pressed
flipImageBox(1);
});
imgTwo.setOnClickListener(v -> {
//call flipImageBox and provide the number of the image button being pressed
flipImageBox(2);
});
imgThree.setOnClickListener(v -> {
//call flipImageBox and provide the number of the image button being pressed
flipImageBox(3);
});
imgFour.setOnClickListener(v -> {
//call flipImageBox and provide the number of the image button being pressed
flipImageBox(4);
});
}