Additional updateQuestion() on buttons


#1

code for setting up next button is like this:

	mNextButton = (ImageButton) findViewById(R.id.next_button);
	mNextButton.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;
			updateQuestion();
		}
	});
	
	updateQuestion();

what i dont get is the last updateQuestion();. why is it there, what is its job?


#2

The last updateQuestion; you have listed there, is the one that initially sets the contents of the question_text_view box.

That updateQuestion is not related to the next_button at all, but is actually the very end of your activity’s onCreate method. onCreate is called by Android, then onCreate sets the button listeners, then onCreate calls updateQuestion to put the first question into the TextView. When you push one of the buttons, it changes the index updateQuestion uses, and calls updateQuestion again to set the TextView to the new question.