Android 如何在textview中计算正确答案和错误答案,并在最后一页显示记分卡
私有void checkAnswer(布尔userPressed){ 你的分数-=1Android 如何在textview中计算正确答案和错误答案,并在最后一页显示记分卡,android,textview,boolean,concatenation,counting,Android,Textview,Boolean,Concatenation,Counting,私有void checkAnswer(布尔userPressed){ 你的分数-=1 } Toast.makeText(MainActivity.this, messageStringId, Toast.LENGTH_SHORT).show(); } mTrueButton=(按钮)findViewById(R.id.true\u按钮) mFalseButton=(按钮)findViewById(R.id.false_按钮) 我有20个问题,对于每个正确答案,我想在your
}
Toast.makeText(MainActivity.this, messageStringId, Toast.LENGTH_SHORT).show();
}
mTrueButton=(按钮)findViewById(R.id.true\u按钮)
mFalseButton=(按钮)findViewById(R.id.false_按钮)
我有20个问题,对于每个正确答案,我想在yourScore变量中加+1,对于每个错误答案,在yourScore变量中减去1。在20个问题的末尾,我想在textview中显示分数,但无法显示。请提前帮助我并感谢。如何在textview中显示yourScore变量的值?可以使用
textView.setText(“您的最终分数是:”+yourScore)
。将textView
替换为您要使用的textView的名称。如何为每个问题返回yourScore变量的值,因为我创建了私有的void方法,每个正确答案我得到1分,每个错误答案得到-1分,但因为我无法将值返回到yourScore变量,这就是原因对于每个答案,它从yourScore=0开始,并给出+1或-1的分数。我想要这些值的总和。因此,最后我可以显示为总分。但由于void方法,无法返回。该怎么办
}
Toast.makeText(MainActivity.this, messageStringId, Toast.LENGTH_SHORT).show();
}
mTrueButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Does nothing yet, but soon!
checkAnswer(true);
mTrueButton.setEnabled(false);
mFalseButton.setEnabled(false);
mMoreInfoButton.setVisibility(View.VISIBLE);
}
});
mFalseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Does nothing yet, but soon!
checkAnswer(false);
mFalseButton.setEnabled(false);
mTrueButton.setEnabled(false);
mMoreInfoButton.setVisibility(View.VISIBLE);
}
});