I want to check if the image of an Image Button equals another image. This is what I have been trying.
if(String.valueOf(image1.getId()) == (selectedQ.image))){
ResultAlertFragment alertDialog = new ResultAlertFragment();
alertDialog.show(getFragmentManager(), "list alert");
}
else if(!(String.valueOf(image1.getId()) == pictureCorrect)){
ResultAlertFragmentIncorrect alertDialog = new ResultAlertFragmentIncorrect ();
alertDialog.show(getFragmentManager(), "list alert");
}
This is where my image selectedQ is set
RandomImage[] questionArray = { imageBoy, imageGirl, imageMan,
imageWoman, imageCow, imageDog, imageCat, imageFox };
// random int for Button
Random randomeQuestion = new Random(System.currentTimeMillis());
int nextQuestion = randomeQuestion.nextInt((questionArray.length) - 1);
selectedQ.person = questionArray[nextQuestion].person;
selectedQ.image = questionArray[nextQuestion].image;
selectedQ.displayed = questionArray[nextQuestion].displayed;
// Selecting a random question
Random randomerSelection = new Random(System.currentTimeMillis());
int randomposition = randomerSelection.nextInt(3);
ImageView imagePosition = (ImageView) findViewById(imageViews[randomposition]);
imagePosition.setImageResource(selectedQ.image);
ArrayList<Integer> imagesAlreadyInUse = new ArrayList<Integer>();
for (int i = 0; i < 4; i++) {
if (!(i == randomposition)) {
int nextImage = 0;
Random randomImageForButtons = new Random(
System.currentTimeMillis());
Boolean condition = false;
while (condition == false) {
nextImage = randomImageForButtons
.nextInt((questionArray.length) - 1);
if (!(nextImage == nextQuestion)) {
if (!(imagesAlreadyInUse
.contains(questionArray[nextImage].image))) {
imagesAlreadyInUse
.add(questionArray[nextImage].image);
condition = true;
}
}
}
int v = imageViews[i];
ImageView iv = (ImageView) findViewById(v);
iv.setImageResource(questionArray[nextImage].image);
questionArray[nextImage].displayed = true;
}
}
tv1.setText(selectedQ.person);
pictureCorrect = String.valueOf(selectedQ.image);
My app asks a user a question. This question is a question object that has a picture and a string. The user must select 1 picture out of 4 that best suits the question. These are randomly generated. I am not sure how to check if they are correct i.e. the picture they selected matches the question.
Can anyone help?