navasmdc / MaterialDesignLibrary

This is a library with components of Android L to you use in android 2.2
Apache License 2.0
8.99k stars 2.22k forks source link

CheckBox setChecked() not working #199

Open THANNPhearum opened 9 years ago

THANNPhearum commented 9 years ago

I tried many time on my Android 5.0.1. For example, mCheckBox.setChecked(true) has nothing affect to UI to show that it checked.

litao0621 commented 9 years ago

+1

SandnerSoft commented 9 years ago

+1

efecanbugday commented 9 years ago

final CheckBox cb = ((CheckBox) findViewById(R.id.checkBox)); cb.post(new Runnable() { @Override public void run() { cb.setChecked(true); } });

bondiep commented 9 years ago

when I use checkbox in xml, if I have an attribute (materialdesign:check="true"). Error occur :( [2015-04-06 04:41:12 - Scanner360](skipping file) [2015-04-06 04:41:12 - Scanner360] /Volumes/Untitled 3/workspace/Scanner360/res/layout/activity_settings.xml:70: error: Error parsing XML: unbound prefix

When I delete it, When running, it throws an exception

java.lang.RuntimeException: Unable to start activity ComponentInfo{...SettingsActivity}: android.view.InflateException: Binary XML file line #70: Error inflating class com.gc.materialdesign.views.CheckBox

My xml : <com.gc.materialdesign.views.CheckBox android:id="@+id/checkbox_auto_protection" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:background="#1E88E5" />

Please help me !

THANNPhearum commented 9 years ago

Hi, As your error message, I think you forget to add this line

xmlns:materialdesign="http://schemas.android.com/apk/res-auto"

to the top of the root layout in your xml.

Example:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:materialdesign="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

   <com.gc.materialdesign.views.CheckBox
                android:id="@+id/add_mode_test_ck"
                android:layout_width="wrap_content"
                android:layout_gravity="center"
                materialdesign:check="true"
                android:background="#1E88E5"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_height="wrap_content" />

</RelativeLayout>
alensiljak commented 9 years ago

thanks, @efecannn ! :+1:

jinkim608 commented 9 years ago

Anyone experiencing the same issue? Even @efecannn 's workaround is not working.

JuanAlejandro commented 9 years ago

The solution @efecannn gave, works for me. Anyway, there'snt other solution?

lopezzbelgium commented 9 years ago

+1

christianscanu commented 9 years ago

Hi, I have the same problem, setchecked is not working. :(

Jdruwe commented 9 years ago

This is still not working + 1

holdtb commented 9 years ago

+1, Thanks @efecannn you saved me a headache

samigehi commented 9 years ago

having same issue

JiabusLee commented 9 years ago

debug it.

mosesmeirelles commented 9 years ago

having same in Android 5.1

jd-alexander commented 9 years ago

@efecannn 's solution worked for me. Running on 5.0

TheFinestArtist commented 9 years ago
new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        checkBox.setChecked(true);
    }
}, 300);
anileger commented 9 years ago

thanks, @efecannn