[英]Score not increasing after the user has scored 1 in Quiz App. How do i fix?
它是一个测验应用程序,它具有用于正确答案和单选按钮的多个选项,当单击正确的单选按钮时,分数必须增加1,除非单选按钮被单击了多少次,并且在“单击下一步”按钮。对我来说,这里的问题是,分数增加一次后就不会增加。 用户正确回答了一个问题后,它将停止进行。 我怎样才能解决这个问题?
我曾尝试更改其运行方式的条件,但它仍然对我不起作用。
RadioButton getClickedButton;
RadioGroup radioGroup;
RadioButton getClickedButton;
Button quit,btnNext;
private int score=0;
boolean clicked=true;
//for button Next
btnNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
radioGroup=(RadioGroup)findViewById(R.id.radioGroup);
getClickedButton=(RadioButton)findViewById(radioGroup.getCheckedRadioButtonId());
try {
if(getClickedButton.getText().equals(answer) ){
if(clicked){
score++;
updateScore(score);
clicked=false;
}
}
}catch (Exception e){
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
if (questionNumber < totalQuestion) {
updateQuestion();
radioGroup.clearCheck(); //to clear the last checked item
} else {
resultIntent();
}
}
});
//for button Next
//quit button
quit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
resultIntent();
}
});
//quit button
}
//Intent for result Activity
public void resultIntent(){
Intent i=new Intent(MainActivity.this,ResultActivity.class);
Bundle dataSend = new Bundle();
dataSend.putInt("SCORING",score);
dataSend.putInt("TOTAL",totalQuestion);
i.putExtras(dataSend);
startActivity(i);
finish();
}
//Intent for result Activity
//to update the score
public void updateScore(int mscore){
showScore.setText("" + mscore);
}
//to update score
请添加此clicked=true;
上面if (questionNumber < totalQuestion)
像这样
clicked=true;
if (questionNumber < totalQuestion)
if(getClickedButton.getText().equals(answer) ){
if(clicked){
score++;
updateScore(score);
clicked=false;
}
}
您正在将“ clicked”变量设置为“ false”,并且永远不会回到true。 您将第一次输入if(click),因为是第一次将其定义为“ true”,而不是将其值设置为“ false”,并且仍为“ false”,因此从第二次开始您单击该按钮,则不会输入“ if”,因为条件为“ false”。
由于缺少部分代码,并且不清楚要在何处使用“ clicked = false”,因此我唯一可以建议的是在另一部分中删除“ clicked = false”或插入“ clicked = true”代码,检查之后。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.