Skip to content
Advertisement

setText inside a void method not updating after call?

@Override
        public void onAnimationEnd(Animation animation) {
            Toast.makeText(PlayQuiz.this, "END", Toast.LENGTH_SHORT).show();

            //Show next question
            showNextQuestion();
            mOptionTwoTextView.setText("Hell Yeah");
        }


private void showNextQuestion() {

        mThisQuestion = mDummyQuestionList.get(mTHisQuestionID++);
        //Set Questions and Options
        mQuestionTextView.setText(mThisQuestion.getQuestion());
        mOptionOneTextView.setText(mThisQuestion.getOptionOne());
        mOptionTwoTextView.setText(mThisQuestion.getOptionTwo());
        mOptionThreeTextView.setText(mThisQuestion.getOptionThree());
        mOptionFourTextView.setText(mThisQuestion.getOptionFour());
    }

inside the animationEnd the set text works perfectly but after calling this void it should change text but it is not changing text.

Advertisement

Answer

@Override
public void onAnimationEnd(Animation animation) {
  
    // execute methods in main thread
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {

            Toast.makeText(PlayQuiz.this, "END", Toast.LENGTH_SHORT).show();
            showNextQuestion();
            mOptionTwoTextView.setText("Hell Yeah");
            
        }
    });

}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement