在我的编码中,m 有三个按钮。我得到选定的按钮是 id 并将其用于比较。但在单击按钮之前,它首先会自动显示默认选定按钮的 id。
rdgp.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
counter++;
if (counter > 5 || counter >= anarray.size()) {
Toast.makeText(testActivity.this, "" + score, 2000).show();
Intent intent = new Intent(testActivity.this, Badge.class);
intent.putExtra("Score", score);
startActivity(intent);
return;
}
rb1.setText(anarray.get(counter));
rb2.setText(an1array.get(counter));
rb3.setText(an2array.get(counter));
rb4.setText(an3array.get(counter));
rb5.setText(an4array.get(counter));
int ans = 0;
if (checkedId == R.id.radio0) {
ans = 1;
} else if (checkedId == R.id.radio1) {
ans = 2;
} else if (checkedId == R.id.radio2) {
ans = 3;
} else if (checkedId == R.id.radio3) {
ans = 4;
}
Toast.makeText(testActivity.this, "" + ans, 2000).show();
if (ans == anarray.get(counter))
;
{
score = score + 1;
}
}
});