Solution to previous Button

#1

mPreviousButton = (Button) findViewById(R.id.previous_button); mPreviousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCurrentIndex = (mCurrentIndex - 1) % mQuestionBank.length; if(mCurrentIndex < 0) mCurrentIndex = 4; updateQuestion(); } });

#2

I think it would be better:

mPreviousButton = (Button) findViewById(R.id.previous_button);
        mPreviousButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                --mCurrentIndex;
                if(mCurrentIndex < 0)
                    mCurrentIndex = mQuestionBank.length - 1;
                updateQuestion();
            }
        });
#3

Thank you so much, my solution was this:

       if (mCurrentIndex == 0) {
            return;
        }
        
        mCurrentIndex = (mCurrentIndex - 1) % mQuestionBank.length;

        updateQuestion();

I think sergei solution is more minimalist and that’s why i end up using his. :slight_smile:

#4

mPrevButton = (Button) findViewById(R.id.prev_button);
mPrevButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if (mCurrentIndex == 0) {
mCurrentIndex = mQuestionBank.length - 1;
}else {
mCurrentIndex = (mCurrentIndex - 1) % mQuestionBank.length;
}
updateQuestion();
}
});