我有 8 对按钮(总共 16 个),其中一些术语来自 sqlite 数据库。我需要当用户连接 8 对(正确或错误,没关系)结束游戏时,最后会有一些弹出窗口。当我在我的代码中放置 counter<7 时,我需要连接 8 对 plus 才能再次单击某些按钮(单击 17 次)。如果我输入计数器<6,那么我会在 7 对和再单击一次(15 次单击)后弹出我的窗口。我不明白这个逻辑。所以这里是代码:
final OnClickListener clickListener = new OnClickListener() {
private Button buttonClicked;
public void onClick(View v) {
if (counter < 7) {
Button button = (Button) v;
button.getBackground()
.setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x003333));
if (buttonClicked == null) {
// first button is clicked
buttonClicked = button;
// only do stuff if buttons are in different layouts
} else {
if (!button.getParent().equals(buttonClicked.getParent())) {
// second button is clicked
if (buttonClicked.getTag().equals(button.getTag())) {
// second button is clicked and same tag but different button
Toast.makeText(Spojnice.this, "Correct", Toast.LENGTH_SHORT).show();
button.getBackground()
.setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0x66FF33));
buttonClicked.getBackground().setColorFilter(
new LightingColorFilter(0xFFFFFFFF, 0x66FF33));
buttonClicked.setEnabled(false);
button.setEnabled(false);
buttonClicked = null;
score.setText("Poeni: " + brojPoenaSpojnice);
counter++;
} else {
counter++;
//reset LightingColorFilter first
button.setEnabled(false);
Toast.makeText(Spojnice.this, "Wrong", Toast.LENGTH_SHORT).show();
buttonClicked = null;
}
} else {
//same button clicked show message or un toggle?
buttonClicked = button;
}
}
} else {
Intent i = new Intent(Spojnice.this, Popup_spojnice.class);
startActivity(i);
mHandler.postDelayed(mLaunchTask, 6500);
}
}
};