【问题标题】:Android vibrations settings - red line under else?Android振动设置 - 其他下的红线?
【发布时间】:2013-04-02 11:25:23
【问题描述】:

我已将这部分代码放在我的设置活动中,因此如果选中正在工作的 xml 文件中的振动框,则将打开振动器,否则将取消它们。但是,else 似乎存在问题,无法让我运行该应用程序。任何帮助将不胜感激,谢谢。

  if (preference instanceof vibrateapp_checkbox=="true");
    Vibrator.vibrate(new long[] { 0, 200, 0 }, 0);
    Else if (preference instanceof vibrateapp_checkbox=="false");
    Vibrator.cancel();

【问题讨论】:

  • 您好,我把它改成了 else 但还是有一条红线写着“删除这个令牌”??
  • 去掉 if 后面的分号 (;)

标签: java android settings vibration android-vibration


【解决方案1】:

不是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();

【讨论】:

  • 您好,我把它改成了 else 但还是有一条红线写着“删除这个令牌”??
  • 你会用什么代替instanceof
  • 什么是 vibrateapp_checkbox 是复选框吗?
  • 干杯,但这里有什么问题:if (vibrateapp_checkbox.isChecked()) vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);振动器.振动(50);否则 vibrator.cancel();
【解决方案2】:

Java 区分大小写。使用 else 而不是 Else

  if (preference instanceof vibrateapp_checkbox=="true")
    {
        Vibrator.vibrate(new long[] { 0, 200, 0 }, 0);
    }
        else if (preference instanceof vibrateapp_checkbox=="false")
    {
        Vibrator.cancel();
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多