作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
GenEdQuestion.class测验形式为多项选择题。我想保存或传输正确答案和所选答案到另一个 Activity (结果)。我转移了分数,但我不知道如何转移结果。我怎样才能做到这一点?
answer1.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (answer1.getText() == mAnswer){
mNumber++;
mScore++;
number.setText(" "+mNumber+" .");
if (mNumber == quizCount){
onFinish();
}
else{
updateQuestion(r.nextInt(mQuestionsLength));
}
}else{
mNumber++;
number.setText(" "+mNumber+" .");
if (mNumber == quizCount){
onFinish();
}
else{
updateQuestion(r.nextInt(mQuestionsLength));
}
}
return false;
}
});
answer2.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (answer2.getText() == mAnswer){
mNumber++;
number.setText(" "+mNumber+" .");
mScore++;
if (mNumber == quizCount){
onFinish();
}
else{
updateQuestion(r.nextInt(mQuestionsLength));
}
}else{
mNumber++;
number.setText(" "+mNumber+" .");
if (mNumber == quizCount){
onFinish();
}
else{
updateQuestion(r.nextInt(mQuestionsLength));
}
}
return false;
}
});
answer3.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (answer3.getText() == mAnswer){
mNumber++;
number.setText(" "+mNumber+" .");
mScore++;
if (mNumber == quizCount){
onFinish();
}
else{
updateQuestion(r.nextInt(mQuestionsLength));
}
}else{
mNumber++;
number.setText(" "+mNumber+" .");
if (mNumber == quizCount){
onFinish();
}
else{
updateQuestion(r.nextInt(mQuestionsLength));
}
}
return false;
}
});
answer4.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (answer4.getText() == mAnswer){
mNumber++;
number.setText(" "+mNumber+" .");
mScore++;
if (mNumber == quizCount){
onFinish();
}
else{
updateQuestion(r.nextInt(mQuestionsLength));
}
}else{
mNumber++;
number.setText(" "+mNumber+" .");
if (mNumber == quizCount){
onFinish();
}
else{
updateQuestion(r.nextInt(mQuestionsLength));
}
}
return false;
}
});
new CountDownTimer(60000*60, 1000){
public void onTick(long secondsLeft){
mCountDownGenEd.setText(""+String.format("%d min, %d sec",
TimeUnit.MILLISECONDS.toMinutes(secondsLeft),
TimeUnit.MILLISECONDS.toSeconds(secondsLeft) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(secondsLeft))));
}
public void onFinish(){
Intent intent = new Intent(getApplicationContext(), GenEdQuestionsResult.class);
intent.putExtra("this", mScore);
startActivity(intent);
}
}.start();
}
private void onFinish() {
Intent intent = new Intent(getApplicationContext(), GenEdQuestionsResult.class);
intent.putExtra("this", mScore);
startActivity(intent);
}
private void updateQuestion(int i) {
question.setText(mQuestions.getQuestion(i));
answer1.setText(mQuestions.getChoice1(i));
answer2.setText(mQuestions.getChoice2(i));
answer3.setText(mQuestions.getChoice3(i));
answer4.setText(mQuestions.getChoice4(i));
mAnswer = mQuestions.getCorrectAnswer(i);
}
GenEdQuestionsResult.class此 Activity 将显示分数以及用户是否通过或失败。我如何将结果放在这里?
mFinalScore = (TextView) findViewById(R.id.scoreTextView);
mResult = (TextView) findViewById(R.id.resultTextView);
int score = getIntent().getIntExtra("this", 0);
mFinalScore.setText(score+" / 20");
if (score <= 10){mResult.setText("Failed");}
else{mResult.setText("Passed");}
这是我想要创建的结果
最佳答案
您有 3 种方法可以做到这一点第一个=>创建一个静态变量,然后你可以在任何你想要的地方访问它,
你可以使用的第二个=>使用intent putExtra
Intent i = new Intent(this, SecondClass.class);
i.putExtra("answer", "myAnswer");
startActivity(i)
第三种方法正在使用sharedPreference,看看这个链接https://developer.android.com/reference/android/content/SharedPreferences.html
关于java - 我如何在其他 Activity 中发送正确答案和所选答案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46900484/
我是一名优秀的程序员,十分优秀!