There are many scenarios in an Android application where you need to instantly react when a preference is changed and update the user interface in some way. When you need to this, you can create a preference listener, an event listener that will let you know when a preference has been updated and let you add code that executes when that happens.
- [Narrator] When you define and manage…your preferences in an activity,…those preferences are saved in something…called the default preference set.…I'll show you how to access that preference set…and I'll also show you how to listen…for changes to any preference set.…In this version of the application,…I've added a new layout file called grid_item.xml.…It places the item image above,…and it places the text view below.…And I'll be using this for a three column grid display.…Now in the main activity, I'll go to my onCreate method.…
And I'll add code right here,…before I call the RecyclerView.…I'll create an instance of the shared preferences class.…I'll name it settings, and I'll get…it's reference with this code.…I'll use a class named PreferenceManager,…and call getDefaultSharedPreferences,…and passing this as the context.…Now I want to find out whether the user…wants to display things in a grid.…That's a boolean value, it was a check box…in the settings screen, and I'll just name it grid.…
And I'll get it's value like this,…
- Modeling data in POJO classes
- Customizing a ListView item display
- Displaying data in a RecyclerView
- Creating a custom array adapter
- Managing shared preferences with Java
- Creating and importing JSON data files
- Accessing SQLite from the command line
- Retrieving data with SQLite queries
Skill Level Intermediate
Android App Development: Data Persistence Librarieswith Annyce Davis3h 59m Intermediate
Android App Development: RESTful Web Serviceswith David Gassner2h 49m Intermediate
1. Display Static Data
2. Store Data in Shared Preferences
About shared preferences4m 41s
3. Store Data in Text Files
4. Manage Relational Data with SQLite
Next steps1m 43s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.