Next button not doing anything


Hi I saw previous discussion regarding this and I tried the resolution but its still not working for me. Could you please help me. Thanks


import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class QuizActivity extends Activity {

private Button mTrueButton;
private Button mFalseButton;
private Button mNextButton;
private TextView mQuestionTextView;

private TrueFalse[] mQuestionBank = new TrueFalse[] {
        new TrueFalse(R.string.question_oceans, true),
        new TrueFalse(R.string.question_mideast, false),
        new TrueFalse(R.string.question_africa, false),
        new TrueFalse(R.string.question_americas,true),
        new TrueFalse(R.string.question_asia, true),

private int mCurrentIndex = 0;

private void updateQuestion() {
    int question = mQuestionBank[mCurrentIndex].getQuestion();

private void checkAnswer(boolean userPressedTrue) {
    boolean answerIsTrue = mQuestionBank[mCurrentIndex].isTrueQuestion();

    int messageResId = 0;

    if (userPressedTrue == answerIsTrue) {
        messageResId = R.string.correct_toast;
    } else {
        messageResId = R.string.incorrect_toast;
    Toast.makeText(this,messageResId, Toast.LENGTH_SHORT).show();

protected void onCreate(Bundle savedInstanceState) {

    mQuestionTextView = (TextView)findViewById(;

    mTrueButton = (Button)findViewById(;
    mTrueButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

    mFalseButton = (Button)findViewById(;
    mFalseButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

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




public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(, menu);
    return true;



You are missing updateQuestion();
mCurrentIndex = (mCurrentIndex + 1 ) % mQuestionBank.length;


I have it there. I deleted the code and retyped it same issue.


It is NOT there in the code you posted above.
Compare very carefully with the code in the book.


Thank you I see what you are saying. I kept looking at the update question outside the curly braces.


Glad to help. :slight_smile: