我正在开发一个简单的测验,其中存储了 50 个问题并随机显示..我的问题是..我如何计算用户回答测验的项目数..例如,我有 50 个问题,如果用户只回答10?所以我希望它在我的分数(对话框)中显示玩家的分数和用户回答的项目数。请帮助我..请..我该怎么做???真的非常感谢帮助!
private OnClickListener finishListener = new OnClickListener() {
public void onClick(View v) {
setAnswer();
//Calculate Score
int score = 0;
int count = 0;
for(int i=0; i<correctAns.length; i++)
{
if ((correctAns[i] != -1) && (correctAns[i] == selected[i]))
score++;
}
count++;
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(Question2.this).create();
alertDialog.setTitle("Your Score");
alertDialog.setMessage("You've got "+(score)+" out of " + (count) + " items");
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE,"Okay", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Question2.this,
MainMenu.class);
startActivity(intent);
}
});
alertDialog.show();
}
};