将动作传递给下一个按钮

Passing actions to the next button

我有 5 个按钮。 当前按钮,按钮 1 正在闪烁。其他人不活跃。用户单击按钮 1 后,按钮 1 上的动画停止,按钮 2 变为活动状态并闪烁。
问题...第一个按钮闪烁,但它不会跳转到按钮 2。我的 case 语句设置有误吗? 这是我到目前为止所得到的...

如有任何帮助,我们将不胜感激。

private int activeButton =1;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_workout_one);

    //setting up the buttons
    Button Button1 = (Button) findViewById(R.id.button_1);
    Button Button2 = (Button) findViewById(R.id.button_2);
    Button Button3 = (Button) findViewById(R.id.button_3);
    Button Button4 = (Button) findViewById(R.id.button_4);
    Button Button5 = (Button) findViewById(R.id.button_5);

    //method to switch between buttons
    buttonClickHandler(Button1, Button2, Button3, Button4, Button5);
}

private void buttonClickHandler(Button a, Button b, Button c, Button d, Button e){

    switch(activeButton++){
        case 1:
            //method to make the button animate etc
            makeButtonActive(a);
            break;
        case 2:

            makeButtonActive(b);
            break;
        case 3:

            makeButtonActive(c);
            break;
        case 4:

            makeButtonActive(d);
            break;
        case 5:

            makeButtonActive(e);
            break;
    }
}

private void makeButtonActive(Button bu){
    //setting up the animation
    Animation mAnimation = new AlphaAnimation(1, 0);
    mAnimation.setDuration(1000);
    mAnimation.setInterpolator(new LinearInterpolator());
    mAnimation.setRepeatCount(Animation.INFINITE);
    mAnimation.setRepeatMode(Animation.REVERSE);
    bu.startAnimation(mAnimation);
    bu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //providing the after click stuff
            v.clearAnimation();
            v.setBackgroundColor(0xFF00FF00);
            v.setFocusable(false);
            v.setFocusableInTouchMode(false);
            v.setClickable(false);
            v.setEnabled(false);
        }
    });
}

它的发生是因为启动动画的方法只被调用一次。单击另一个按钮时需要调用它。

称之为

buttonClickHandler(Button1, Button2, Button3, Button4, Button5);

onClick()中并在class级别定义所有按钮

编辑

private int activeButton =1;
Button Button1;
Button Button2;
Button Button3;
Button Button4;
Button Button5;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_workout_one);

    //setting up the buttons
    Button1 = (Button) findViewById(R.id.button_1);
    Button2 = (Button) findViewById(R.id.button_2);
    Button3 = (Button) findViewById(R.id.button_3);
    Button4 = (Button) findViewById(R.id.button_4);
    Button5 = (Button) findViewById(R.id.button_5);
    buttonClickHandler(Button1, Button2, Button3, Button4, Button5);
}

private void buttonClickHandler(Button a, Button b, Button c, Button d, Button e){ 
    switch(activeButton++){
        case 1:
            //method to make the button animate etc
            makeButtonActive(a);
            break;
        case 2:
            makeButtonActive(b);
            break;
        case 3:
            makeButtonActive(c);
            break;
        case 4:
            makeButtonActive(d);
            break;
        case 5:
            makeButtonActive(e);
            break;
    }
}

private void makeButtonActive(Button bu){
    //setting up the animation
    Animation mAnimation = new AlphaAnimation(1, 0);
    mAnimation.setDuration(1000);
    mAnimation.setInterpolator(new LinearInterpolator());
    mAnimation.setRepeatCount(Animation.INFINITE);
    mAnimation.setRepeatMode(Animation.REVERSE);
    bu.startAnimation(mAnimation);
    bu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //providing the after click stuff
            v.clearAnimation();
            v.setBackgroundColor(0xFF00FF00);
            v.setFocusable(false);
            v.setFocusableInTouchMode(false);
            v.setClickable(false);
            v.setEnabled(false);
            buttonClickHandler(Button1, Button2, Button3, Button4, Button5);
        }
    });
}

注意:变量名不应以大写字母开头