我的增量++和减量 - 按钮在Android中不能完美运行?

时间:2014-03-16 21:07:14

标签: android switch-statement

我有两个按钮,即“下一个”和“上一个”,通过使用这些按钮,我更改了三个图像,但这些按钮不能正常工作,我的意思是在完成它的圆圈之后需要2个额外的空格才能转到上一个按钮点击

简单来说,我想要:
  1 next 2 next 3 previous 2 previous 1 next 2 next 3 previous 2 previous 1.

但这发生在我身上: 1下一个2下一个3上一个2上一个3上一个2上一个1下一个2下一个1下一个2 我怎么解决它?

 My java code:
         int counter = 1;

     // my next Button
      public void nextClick(View v) {
    try {
        switch (counter) {
        case 1: // first click
            img1.setImageResource(myImageViewList1[0]);
            imgBut1.setImageResource(myImageButtonList1[0]);
            imgBut2.setImageResource(myImageButtonList2[0]);    
            break;
        case 2: // second click
            img1.setImageResource(myImageViewList1[1]);
            imgBut1.setImageResource(myImageButtonList1[1]);
            imgBut2.setImageResource(myImageButtonList2[1]);
            break;
        case 3: // third click
            img1.setImageResource(myImageViewList1[2]);
            imgBut1.setImageResource(myImageButtonList1[2]);
            break;
        default:
            break;
        }

    } catch (Exception e) {
    }
     counter++; 
}

// my previous Button
  public void previousClick(View v) {
    try {
        switch (counter) {

        case 3: // third click
            img1.setImageResource(myImageViewList1[2]);
            imgBut1.setImageResource(myImageButtonList1[2]);
            imgBut2.setImageResource(myImageButtonList2[2]);
            break;
        case 2: // second click
            img1.setImageResource(myImageViewList1[1]);
            imgBut1.setImageResource(myImageButtonList1[1]);
            imgBut2.setImageResource(myImageButtonList2[1]);
            break;
        case 1: // first click
            img1.setImageResource(myImageViewList1[0]);
            imgBut1.setImageResource(myImageButtonList1[0]);
            imgBut2.setImageResource(myImageButtonList2[0]);
            break;
        default:
            break;
        }

    } catch (Exception e) {
    }
    counter--;
}
}

0 个答案:

没有答案