im trying to randomize images when button clicked and if the image is what i want it to be, randomize again, but if its not, close the activity.
in my code i cant randomize, it closes always, but if i delete finish function, it will randomize normally.
i just want that imageview recognize the image without a sqlite DB
@Override
public void onClick(View v) {
int[] cards={R.drawable.bg,R.drawable.bg1};
Random r = new Random();
int n = r.nextInt(2);
ImageView imgview1 = (ImageView) findViewById(R.id.imgv1);
imgview1.setImageResource(cards[n]);
if (imgview1.equals(R.drawable.bg){
imgview1.setImageResource(cards[n]);
}
else {
finish();
}
}
Aucun commentaire:
Enregistrer un commentaire