gpt4 book ai didi

java - 我如何在其他 Activity 中发送正确答案和所选答案?

转载 作者:行者123 更新时间:2023-12-01 20:09:28 27 4
gpt4 key购买 nike

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");}

这是我想要创建的结果

this is the picture of result i want to create

最佳答案

您有 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com