Additional updateQuestion() on buttons


code for setting up next button is like this:

	mNextButton = (ImageButton) findViewById(;
	mNextButton.setOnClickListener(new View.OnClickListener() {
		public void onClick(View v) {
			mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;

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


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.