我已将这段代码放入我的设置 Activity 中,因此如果选中正在工作的 xml 文件中的振动框,则振动器将打开,否则将被取消。但是,其他似乎存在问题,不允许我运行该应用程序。任何帮助将不胜感激,谢谢。
if (preference instanceof vibrateapp_checkbox=="true");
Vibrator.vibrate(new long[] { 0, 200, 0 }, 0);
Else if (preference instanceof vibrateapp_checkbox=="false");
Vibrator.cancel();
最佳答案
它不是Else
而是else
。 java 区分大小写。此外,else
没有if
,因为你通过(;)
if (preference instanceof vibrateapp_checkbox=="true")
Vibrator.vibrate(new long[] { 0, 200, 0 }, 0);
else if (preference instanceof vibrateapp_checkbox=="false")
Vibrator.cancel();
此外,这似乎是不正确的
(preference instanceof vibrateapp_checkbox=="false")
因为在 instanceof
之后,type
预计不是值
您可以将其更正为
if (vibrateapp_checkbox.isChecked())
Vibrator.vibrate(new long[] { 0, 200, 0 }, 0);
else
Vibrator.cancel();
关于java - Android 振动设置 - else 下的红线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15762877/