Preference Activity

android - November 13, 2011 10:04:16 PM EST

PreferenceActivity on android

PreferenceActivity on android

Search Google for: PreferenceActivity on android

Search Android Developers Group for: PreferenceActivity on android

Search Android Beginers Group for: PreferenceActivity on android

Search Google Code for: PreferenceActivity on android

Search Android Issues Database for: PreferenceActivity on android

android - November 20, 2011 9:37:14 AM EST

SDK Reference

SDK Reference

android - November 20, 2011 10:02:15 AM EST

Types of Controls in Preferences

Types of Controls in Preferences

android - November 20, 2011 11:48:41 AM EST

Sample for Check Box Preference


<CheckBoxPreference android:key="audio_preference" 
android:title="Turn on/off Sound" 
android:summary="Use this to turn on and off the sound"></CheckBoxPreference>

android - November 20, 2011 11:50:29 AM EST

Sample for list Preference


<ListPreference android:summary="Select the time window for a game" 
                 android:dialogTitle="Choose One From Below" 
                 android:key="gametime_preference" 
                 android:title="Game Time"
                 android:entries="@array/timewindows"
                 android:entryValues="@array/timewindows_values"/>

android - November 20, 2011 11:52:28 AM EST

Activity Code Wiring for Preference


import android.os.Bundle;
import android.preference.PreferenceActivity;

public class GameSettingsActivity extends PreferenceActivity{

   /**
    * First method to be called when activity is created. 
    * This method will do all the initial setups and initializations.
    * 
    */
   public void onCreate(Bundle savedInstanceState) {
        
      super.onCreate(savedInstanceState);
        
      /**
       * Setting the view
       */
      addPreferencesFromResource(R.xml.game_preferences);
        
      
    }
}

android - November 20, 2011 11:55:08 AM EST

How do i default preferences?

How do i default preferences?

android - November 20, 2011 11:55:43 AM EST

Defaulting Preferences in Android Preference Activity

Defaulting Preferences in Android Preference Activity

Search for: Defaulting Preferences in Android Preference Activity

android - November 20, 2011 11:57:21 AM EST

Initializing the default values from the Preference Xml

Initializing the default values from the Preference Xml

android - November 20, 2011 11:59:39 AM EST

How to Default Preference for List Preference in Preference XML?


<ListPreference android:summary="Select the time window for a game" 
                 android:dialogTitle="Choose One From Below" 
                 android:key="gametime_preference" 
                 android:title="Game Time"
                 android:entries="@array/timewindows"
                 android:entryValues="@array/timewindows_values"
                 android:defaultValue="1"/>

android - November 20, 2011 11:59:39 AM EST

How to Default Preference for List Preference in Preference XML?


<ListPreference android:summary="Select the time window for a game" 
                 android:dialogTitle="Choose One From Below" 
                 android:key="gametime_preference" 
                 android:title="Game Time"
                 android:entries="@array/timewindows"
                 android:entryValues="@array/timewindows_values"
                 android:defaultValue="1"/>

android - November 20, 2011 12:11:05 PM EST

Somehow My List preference is not working --> I solved it read the next section

This is what i know i defined two arrays one for the entries and another for the entry values. Both were of type arrays.

But its not working. List preference in giving a null pointer exception when defaulting to a value.

Sample as below


   <array name="timewindows">
      <item>2 Minutes</item>
      <item>3 Minutes</item>
      <item>5 Minutes</item>
   </array>   
   
   <array name="timewindows_values">
      <item>1</item>
      <item>2</item>
      <item>3</item>
   </array>

Deepak Nenmini - November 20, 2011 12:12:31 PM EST

How did i solve the above issue?

I have to change the array to string-array and this solves it. Please remember this is a common issue everyone will face.

Changed the code as below and all my issues were solved..Thanks to string-array.


   <string-array name="timewindows">
      <item>2 Minutes</item>
      <item>3 Minutes</item>
      <item>5 Minutes</item>
   </string-array>   
   
   <string-array name="timewindows_values">
      <item>1</item>
      <item>2</item>
      <item>3</item>
   </string-array>

Deepak Nenmini - November 20, 2011 12:14:11 PM EST

Well How do i change the preference screen background?

Well How do i change the preference screen background?

Deepak Nenmini - November 20, 2011 12:17:49 PM EST

Yes we can use theming to change the background. Default background is always better as it matched all other android preferences.

Yes we can use theming to change the background. Default background is always better as it matched all other android preferences.

But let me still try to change the background using theming.