ListPreference Example

This example shows how you can use list preference in android. ListPreference A Preference that displays a list of entries as a dialog. This preference will store a string into the SharedPreferences.

Algorithm:

1.) Create a new project by File-> New -> Android Project name it ListPreferenceExample.

2.) Write following into main.xml:

 

 

3.) Create and write following into res/xml/preference.xml:

 

 

 

4.) Create and write following into res/values/arrays.xml:

 

 

 

5.) Add following activity to your manifest.

 

6.) Create and write following into PrefActivity.java:

 

 

7.) Create and write following into PrefFragment.java:

 

 

8.) Run for output.

Steps:

1.) Create a project named ListPreferenceExample and set the information as stated in the image.

Build Target: Android 4.3
Application Name: ListPreferenceExample
Package Name: com.example. ListPreferenceExample
Activity Name: ListPreferenceExampleActivity

2.) Open ListPreferenceExampleActivity.java file and write following code there:

 

 

3.) Compile and build the project.

Output