我已经提供了 4 个问题的 xml 和 java 代码。我在其中工作,每个问题都有 4 个单选按钮,在 javam 中,如果用户选择正确的答案,那么最后必须添加分数。结果必须显示姓名和分数,但我似乎无法从那里继续
Java类:
public class MainActivity extends AppCompatActivity {
int score = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public int answersQ1(View view) {
RadioButton aq1 = (RadioButton) findViewById(R.id.GQ11);
RadioButton aq2 = (RadioButton) findViewById(R.id.GQ12);
RadioButton aq3 = (RadioButton) findViewById(R.id.GQ13);
RadioButton aq4 = (RadioButton) findViewById(R.id.GQ14);
if (aq1.isChecked()) {
score = score + 1;
} else if (aq2.isChecked() && (aq3.isChecked() && (aq4.isChecked()))) {
score = score + 0;
}
return score;
}
public int answersQ2(View view) {
RadioButton ab1 = (RadioButton) findViewById(R.id.GQ21);
RadioButton ab2 = (RadioButton) findViewById(R.id.GQ22);
RadioButton ab3 = (RadioButton) findViewById(R.id.GQ23);
RadioButton ab4 = (RadioButton) findViewById(R.id.GQ24);
if (ab2.isChecked()) {
score = score + 1;
} else if (ab1.isChecked() && (ab3.isChecked() && (ab4.isChecked()))) {
score = score + 0;
}
return score;
}
public int answersQ3(View view) {
RadioButton ac1 = (RadioButton) findViewById(R.id.GQ31);
RadioButton ac2 = (RadioButton) findViewById(R.id.GQ32);
RadioButton ac3 = (RadioButton) findViewById(R.id.GQ33);
RadioButton ac4 = (RadioButton) findViewById(R.id.GQ34);
if (ac2.isChecked()) {
score = score + 1;
} else if (ac1.isChecked() && (ac3.isChecked() && (ac4.isChecked()))) {
score = score + 0;
}
return score;
}
当我按下提交按钮时,应用程序崩溃。
呼唤远方
相关分类