安卓前进后退按钮怎么实现

安卓前进后退按钮如何实现?
前进按钮有了下面是代码,不过看不太懂,请大神解释一下,另外请帮忙写个后退按钮代码。
nextButton = (Button) findViewById(R.id.nextbutton);
        nextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) 
                currectIndex = (currectIndex + 1) % questionBank.length;//请问这句神马意思?
                updateQuestion();
            }
        });

------解决思路----------------------
引用:
Quote: 引用:

Quote: 引用:

Quote: 引用:

题库?上一题下一题功能?currentIndex是谁的下标?建议贴全面一点的代码。

如果currentIndex是数组questionBank的下标的话,那么currentIndex永远小于questionBank.length。因此 currectIndex = (currectIndex + 1) % questionBank.length; 当cunrrentIndex<=questionBank.length的时候,这句代码就相当于currectIndex = currectIndex + 1;用取余的方式的原因是currectIndex=questionBank.length的时候再+1数组下标就会越界,用取余的方式当在最后一题点击前进的时候能进入第一题,形成循环,所以这就话的功能就是下标向后移动一位。之后会调用updateQuestion();更新当前显示的题目。

一不小心发出去了,下面说上一题的功能,下一题是把下标往后移一位,那么上一题自然就是往前移一位,加1变成减1就行了。

currentIndex -= 1;
if (currentIndex == -1) { // 第一题再后退则进入最后一题
  currentIndex = questionBank.length - 1;
}
updateQuestion();
没法用,能不能模仿下一题写个?


preButton = (Button) findViewById(R.id.prebutton);
preButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) 
       currentIndex -= 1;
       if (currentIndex == -1) { // 第一题再后退则进入最后一题
          currentIndex = questionBank.length - 1;
       }
       updateQuestion();
    }
});