gpt4 book ai didi

java - 将操作传递给下一个按钮

转载 作者:太空宇宙 更新时间:2023-11-04 14:15:17 25 4
gpt4 key购买 nike

我有 5 个按钮。当前按钮,按钮 1 正在闪烁。其他人都不活跃。一旦用户单击按钮 1,按钮 1 上的动画就会停止,按钮 2 变为 Activity 状态并闪烁。
问题...第一个按钮闪烁,但它没有跳转到按钮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() 中并在类级别定义所有按钮

编辑

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);
}
});
}

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

关于java - 将操作传递给下一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27829334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com