2

I have a following preference in my xml file:

<?xml version="1.0" encoding="utf-8"?>
<CheckBoxPreference android:title="Alert" android:widgetLayout="@layout/preference_checkbox" android:key="alert"
    />

I wanted to make my own custom checkbox, so as you can see above I gave this preference "android:widgetLayout" parameter, which links to this file:

<CheckBox 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/checkbox"
android:id="@+id/alert">

Problem: With (widgetLayout) parameter, it doesn't save the checkbox value. So if I open preferences CheckBox is checked. Then if I uncheck it, and open preferences again, the value from before is not stored, or it does not persist. I don't have that problems if I use CheckBoxPreference without parameter "android:widgetLayou", which in this case, value is stored.

Any ideas?

rootpanthera
  • 2,731
  • 10
  • 33
  • 65

1 Answers1

4

You can simply fix it by:

1- change the checkbox id to android:id="@android:id/checkbox

2- set these 3 attrs:

android:focusableInTouchMode="false"

android:clickable="false"

android:focusable="false"

<CheckBox 
 android:id="@android:id/checkbox"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:button="@drawable/checkbox"
 android:clickable="false"
 android:focusable="false"
 android:focusableInTouchMode="false" >
Alireza Sobhani
  • 769
  • 1
  • 8
  • 18