Android Studio复选框输出不正确的值

时间:2019-05-19 00:04:56

标签: javascript android

已选中Checkbox方法返回不正确的相反值。选中此复选框时,ischecked为false。不确定我在这里做错了吗?

XML代码:

<CheckBox
    android:id="@+id/whipped_cream_checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16dp"
    android:buttonTint="#673AB7"
    android:checked="false"
    android:focusable="auto"
    android:paddingLeft="24dp"
    android:text="Whipped Cream"
    android:textSize="16sp" />

Java代码:

    public void submitOrder(View view) {
        CheckBox WhippedCreamCheckBox = findViewById(R.id.whipped_cream_checkbox);
        boolean hasWhippedCream = WhippedCreamCheckBox.isChecked();
        Log.v("MainActivity","Has whipped cream: " + hasWhippedCream);
        int price = calculatePrice();
        String priceMessage = createOrderSummary(price, hasWhippedCream);
        displayMessage(priceMessage);
    }

When checkbox is checked - ischecked output should be true
Wh

en复选框未选中-ischecked输出应为false

0 个答案:

没有答案
相关问题