Open THANNPhearum opened 9 years ago
+1
+1
final CheckBox cb = ((CheckBox) findViewById(R.id.checkBox)); cb.post(new Runnable() { @Override public void run() { cb.setChecked(true); } });
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 !
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>
thanks, @efecannn ! :+1:
Anyone experiencing the same issue? Even @efecannn 's workaround is not working.
The solution @efecannn gave, works for me. Anyway, there'snt other solution?
+1
Hi, I have the same problem, setchecked is not working. :(
This is still not working + 1
+1, Thanks @efecannn you saved me a headache
having same issue
debug it.
having same in Android 5.1
@efecannn 's solution worked for me. Running on 5.0
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
checkBox.setChecked(true);
}
}, 300);
thanks, @efecannn
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.