我一直在试图弄清楚这一点,但随着每次更改,新错误都会出现。我想要做的是存储数字选择器中的值(我可以看到其中的2个),然后可以稍后使用这些值。我想在下面的Toast消息中使用它们,以及在解决此问题后,在一个名为倒计时的新活动中使用它们。我收到错误消息,指出在MyListener和MyListener2类下mainTime和snoozeTime是多余的,而当我尝试在我的字符串中使用它们时,“无法解析符号”。无法解决符号错误
public void openCD(View v) {
class MyListener implements NumberPicker.OnValueChangeListener {
@Override
public void onValueChange(NumberPicker numberPickerMain, int oldVal, int newVal) {
int mainTime = newVal;
}
}
class MyListener2 implements NumberPicker.OnValueChangeListener {
@Override
public void onValueChange(NumberPicker numberPickerSnooze, int oldVal, int newVal) {
int snoozeTime = newVal;
}
}
String confirmation = "Your shower is set for " + MyListener.mainTime + " minutes with a "
+ MyListener2.snoozeTime + " minute snooze. Enjoy your shower!";
Toast.makeText(this.getApplicationContext(), confirmation, Toast.LENGTH_LONG).show();
Intent countdown=new Intent(this, CountDown.class);
startActivity(countdown);
}
声明你的'mainTime,snoozeTime'水珠盟友在方法之外访问其值。 – GrIsHu 2014-09-03 05:20:12