I am new to android development trying to understand how we save default preferences. I have following settings layout file:
<RadioGroup android:id="@+id/rg"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rb1" android:checked="true"
android:text="RadioButton1">
</RadioButton>
<RadioButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rb2" android:text="RadioButton2" android:checked="true">
</RadioButton>
<RadioButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rb3" android:text="RadioButton3">
</RadioButton>
</RadioGroup>
<CheckBox
android:id="@+id/ch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chk_ios" />
<CheckBox
android:id="@+id/ch2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chk_android"
android:checked="true" />
<CheckBox
android:id="@+id/ch3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chk_windows" />
I want that when user first opens the app and goes to settings view rb1 and ch1 should be checked by default. I wrote following code in main.java file:
PreferenceManager.setDefaultValues(this, R.xml.pref, false);
My question is how to create pref.xml file for above?
I have this so far:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference android:title="Function"
android:defaultValue="true"
android:summary="ch1 should be default checked"
android:key="functionDefault" />
</PreferenceScreen>
What are required fields for checkbox in the xml file? Also how to create pref.xml for radio button?