Professional Documents
Culture Documents
UNIT3 s2
UNIT3 s2
Session 2
Preference Framework and Activity (Settings)
• PreferenceActivity
– public abstract class PreferenceActivity extends ListActivity implements
PreferenceFragment. OnPreference Start FragmentCallback
• PreferenceFragment
– public abstract class PreferenceFragment
extends Fragment
• Preference
– form of a ListView.
– This class provides the View to be displayed in the activity and
associates with a SharedPreferences to store/retrieve the
preference data.
Contd..,
• The preference hierarchy can be formed in
multiple ways:
– From an XML file specifying the hierarchy
– From different Activity that each specify its own
preferences in an XML file via Activity meta-data
– From an object hierarchy rooted with
PreferenceScreen
• <?xml version="1.0" encoding="utf-8"?>
• <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
• <PreferenceCategory
• android:summary="Username and password information"
• android:title="Login information" >
• <EditTextPreference
• android:key="username"
• android:summary="Please enter your login username"
• android:title="Username" />
• <EditTextPreference
• android:key="password"
• android:summary="Enter your password"
• android:title="Password" />
• </PreferenceCategory>
•
• <PreferenceCategory
• android:summary="Username and password information"
• android:title="Settings" >
• <CheckBoxPreference
• android:key="checkBox"
• android:summary="On/Off"
• android:title="Keep me logged in" />
•
• <ListPreference
• android:entries="@array/listOptions"
• android:entryValues="@array/listValues"
• android:key="listpref"
• android:summary="List preference example"
• android:title="List preference" />
• </PreferenceCategory>
• </PreferenceScreen>
Static File as Resource
• externalize app resources
• access them using resource IDs