【问题标题】:Cannot Resolve symbol 'isChecked()'无法解析符号“isChecked()”
【发布时间】:2021-02-08 17:58:16
【问题描述】:

我正在尝试检查单选按钮是否被选中。在此基础上,我会触发一些动作。我搜索并发现 "isChecked" 是这样做的方法。我使用该方法,但 android studio 说 Cannot Resolve symbol 'isChecked()'。

<CheckBox
        android:id="@+id/cream"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:checked="false"

        android:paddingLeft="26dp"
        android:text="Whipped Cream"
        android:textSize="16sp" />

final CheckBox box = (CheckBox) findViewById(R.id.cream);
     if (box.isChecked())
     {
    box.setChecked(false);
}

提前谢谢你。

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

现在有类似的问题,用v

final CheckBox whipped_cream_variable = (CheckBox) findViewById(R.id.whipped_cream);
boolean whipped_cream_has = whipped_cream_variable.isChecked();
Log.v("MainActivity", "Has whipped cream:" + whipped_cream_has);

【问题讨论】:

  • 你导入了需要的东西吗?您是否尝试过清理和重建项目?
  • 到目前为止,我已经导入了以下 import android.os.Bundle;导入android.util.Log;导入android.view.View;导入 android.widget.CheckBox;导入 android.widget.TextView;导入 androidx.appcompat.app.AppCompatActivity;
  • 我刚刚复制了您的代码,它在这里运行良好。您是否尝试退出框架并再次打开它?清理项目并重建它?
  • 对丹·巴鲁克有效。谢谢你。现在我遇到了类似的问题,现在使用“v”
  • 很高兴它正在工作。不确定您还有什么其他问题?

标签: android xml android-activity checkbox ischecked


【解决方案1】:

Dan Baruch 解决了这个问题

  1. 尝试清理并重建项目 和
  2. 尝试将语句放在触发按钮中

【讨论】:

    猜你喜欢
    • 2018-11-11
    • 1970-01-01
    • 1970-01-01
    • 2021-02-04
    • 2016-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多