J'ai un ensemble de ImageView dans lequel certains d'entre eux sont de couleur rouge clignotent pendant un certain temps comme ci-dessous.Comment comparer les ID ImageView sur un événement click?
Je veux le faire, quand je suis cliquez sur couleur cligna des yeux imageViews il change comme marque tic et quand je suis cliquez sur non cligné des yeux imageViews il changer marque comme croix.
Mon problème est mon code actuel seulement pour l'imageview et tous les autres imageViews sont marqués.
Comment faire pour marquer plus d'un ImageView.
Voici mon code:
org_id = new int[]{R.id.img1_1, R.id.img1_2, R.id.img1_3, R.id.img1_4};
all = new int[]{R.id.img1_1, R.id.img1_2, R.id.img1_3, R.id.img1_4};
Random random = new Random();
for(int j=0;j<2;j++) {
id = all[random.nextInt(all.length)];
ObjectAnimator animator = ObjectAnimator.ofInt(findViewById(id), "backgroundResource", R.drawable.new_stateimg, R.drawable.org_state).setDuration(2000);
Toast.makeText(Game.this, "index" + findViewById(id), Toast.LENGTH_LONG).show();
animator.setEvaluator(new ArgbEvaluator());
animator.start();
for (int i=0; i < org_id.length; ++i) {
final int btn = org_id[i];
findViewById(btn).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if ((findViewById(id)).equals(findViewById(btn)))
{
findViewById(id).setBackgroundResource(R.drawable.correct);
} else {
Toast.makeText(Game.this, "wrong", Toast.LENGTH_SHORT).show();
findViewById(btn).setBackgroundResource(R.drawable.cross);
}
}
});
}
}
qu'est-ce que getId? .. –
maintenant voir mon événement onClick. J'espère que cela vous aidera. –
Le premier getDrawable a une erreur. –