Creating Setting in android JAVA using Preferences

Опубликовано: 09 Апрель 2026
на канале: CyberArmory
88
3

What is Preferences?

In Android Java, preferences are user-configurable settings that can be stored in a file or database.
They are a way for users to customize the behavior of an app or to store their personal data.

Preferences are typically implemented using the `Preference` class.
This class provides a number of different types of preferences, such as `SwitchPreference`, `ListPreference`,
and `EditTextPreference`. Each type of preference has a different way of storing and displaying its value.

Preferences can be used to store a wide variety of settings, such as the app's theme,
the user's preferred language, and the user's contact information.
They can also be used to store personal data, such as the user's login credentials or their shopping cart contents.




Here are the steps, how to create and implements preferences in android using java
1.First I want to create a preference.xml file under res/xml directory ..
2.Now I want to add different types of Preferences to this files , Such as SwitchPreference,ListPreference ..... other
I will add them in preference category first

for creating listPreference,first I have to create two arrays, one for list items and one for listvalues
I will create arrays under res/values directory


3.Now I am going to create SettingFragment class extending PreferenceFragment or PreferenceFragmentCompat class in MainActivity.java file
4. Now I want to implment its method onCreatePreferences()
5. NOw I want to inflate preference file here ,to be shown in settingFragment with setPreferencesFromResource() method

6. Now I want to bind each Preference with findPReference()

Our Preferences are created ,now I want to add Listener to each of this

FOr this purpose we will do these steps
1.implments Preferenc.onPreferenceChangeLister in SettingFragement
2.Implements its method onPreferenceChange

now We successfully created and Implemented Preferences,
in next video we will do or add some setting Functionality to this video
Thanks .....