Saturday, 12 September 2015

Preference xml Activity and check Boxes

To create a Different activity of Preferences

first we need to a have a button or so to take it that activity

Create preference xml file and a java file for the layout

The xml is create as type preference and goes to the xml directory

Adding checkBoxes to the xml file

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference android:key="first"    android:title="first"    android:summary="this is the first option"></CheckBoxPreference>
    <CheckBoxPreference android:key="Second"        android:title="SEcond"        android:summary="this is the Second option"></CheckBoxPreference>

</PreferenceScreen>

The java file of Preference Activity is bit different 

the class Extends preference Activity

It doesnt use set content view but uses
addPreferencesFromResource(R.xml.pref);

add the class to the manifest




Being a prefernece thing itself we dont need to save it while onstop and all


No comments:

Post a Comment