我正在尝试检查单选按钮是否被选中。在此基础上,我会触发一些动作。我搜索并发现“isChecked”是这样做的方法。我使用该方法,但android studio说 无法解析符号 '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);