在我的編碼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;
}
}
});
它顯示的默認值是 – Khan