Next button not updating with next question


#1

Hey there,

I’m up to Updating the Controller Layer and testing my next button but I cannot for the life of me work out why my next button isn’t updating with the next question in the array. I’ve gone over my code a few times and cant find any errors. Sorry for the code dump but maybe someone else can see some mistake I’ve made?

package com.fiixed.android.geoquiz;

import android.app.Activity;
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();
    mQuestionTextView.setText(question);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quiz);
    
    mQuestionTextView = (TextView)findViewById(R.id.question_text_view);
    
    
    mTrueButton = (Button)findViewById(R.id.true_button);
    mTrueButton.setOnClickListener(new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			Toast.makeText(QuizActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show();
			
		}
	});
    mFalseButton = (Button)findViewById(R.id.false_button);
    mFalseButton.setOnClickListener(new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			Toast.makeText(QuizActivity.this, R.string.correct_toast, Toast.LENGTH_SHORT).show();
			
		}
	});
    mNextButton = (Button)findViewById(R.id.next_button);
    mNextButton.setOnClickListener(new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;
			
		}
	});
    updateQuestion();
}


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

}


#2

OK, I think I solved it myself. Seems my reference ID’s for the true and next buttons in R.java were mixed up? I don’t know how that happened.

I just went into activity_main.xml, deleted the reference ID attributes then remade them. fixed the problem.

weird.