Listener on TextView

I cant seem to get my listener on textview to work properly. My code is as follows

mQuestionTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View w) {
updateQuestion();
}
});

You have to update the mCurrentIndex in order to go to the next question.

mQuestionTextView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;
updateQuestion();
}
});

When I clicked on the last question, I had errors. why??

My solution:

    View.OnClickListener nextQuestionListener;

    mNextButton.setOnClickListener
            (nextQuestionListener = new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    mCurrentIndex = ++mCurrentIndex % mQuestionBank.length;
                    updateQuestion();
                }
            });

    mQuestionTextView.setOnClickListener(nextQuestionListener);
1 Like

Make sure you have the mod (%) for
mCurrentIndex = (mCurrentIndex + 1)% mQuestionBank.length;

it shows the 1st question after it hits the last question