Androidアプリで作業を開始し、スコアを得るためにクイズを完了する必要があるクイズアプリを開始しました。しかしsetText
とsetImage
をResultActivity
に更新できません。クイズをQuizActivity
で終了すると、ResultActivity
はスコアのみを更新するだけで、画面に必要なテキストと画像は更新されません。UIが自動的にアップデートされていません。更新後にのみ変更されます。
ここにコードがありますが、私はsetText
に基づいて "スコア"に基づいていますが、変更を確認するためにUIを更新する必要があります。私は別のアクティビティからスコアを渡して、スコアに基づいてテキストを変更します。私に助けてください、前もって感謝します。
//code for QuizActivity
private void updateQuestion(){
if(mQuestionNumber < mQuestionLibrary.getLength()){
mQuestionView.setText(mQuestionLibrary.getQuestion(mQuestionNumber));
mButtonChoice1.setText(mQuestionLibrary.getChoice(mQuestionNumber, 1));
mButtonChoice2.setText(mQuestionLibrary.getChoice(mQuestionNumber, 2));
mButtonChoice3.setText(mQuestionLibrary.getChoice(mQuestionNumber, 3));
mButtonChoice4.setText(mQuestionLibrary.getChoice(mQuestionNumber,4));
mAnswer = mQuestionLibrary.getCorrectAnswer(mQuestionNumber);
mQuestionNumber++;
}
else {
Intent intent = new Intent(QuizActivity.this, ResultActivity.class);
intent.putExtra("score", mScore);
// pass the current score to the second screen
startActivity(intent);
//The Following is the code for ResultActivity
Intent intent = getIntent();
int score = intent.getIntExtra("score", 0);
SharedPreferences mypref = getPreferences(MODE_PRIVATE);
int highscore = mypref.getInt("highscore", 0);
if (highscore < score) {
txtScore.setText("Your Score: " + score + " /10");
SharedPreferences.Editor editor = mypref.edit();
editor.putInt("highscore", score);
editor.commit();
}
else {
int score1 = score + highscore;
txtScore.setText(" Your score: " + score1 + " /10");
SharedPreferences.Editor editor1 = mypref.edit();
editor1.putInt("highscore", score1);
editor1.commit();
}
if (highscore == 0) {
image1.setVisibility(View.GONE);
txtScore.setVisibility(View.GONE);
resulttext.setText("INSTRUCTION \n" +
"\n" +
"1) CLICK on ‘hello!’\n" +
"\n" +
"2) VISIT hello\n" +
"\n" +
"3)EE" +
"\n" +
"4)EE!");
btnscan.setText("abc!");
}
else if (highscore == 1 & highscore < 2) {
resulttext.setText("Well Done!");
image1.setImageResource(R.drawable.bubble);
btnscan.setText("Let's bubble on");
}
else if (highscore >= 3) {
resulttext.setText("These are good practices to learn.\n" +
"\n" +
"Bloop bloop~");
image1.setImageResource(R.drawable.lightbulb);
btnscan.setText("Let’s keep swimming");
}
}
}
あなたは言う: >私はResultActivityのsetTextとsetImageを更新できません。よく: 'setText'と' setImage'はメソッドではありません。私はTextViewとImageViewを意味すると思いますが、それはあなたが意味するものです。 –
こんにちは@Ali Zeynaliは、ResultActivity.if(ハイスコア== 0){resulttext.settext( "xxx"); –