- Android Wear Projects
- Ashok Kumar S
- 126字
- 2021-07-15 17:17:57
Fetching all the saved notes from SharedPreference
Fetching all the notes for this List type method needs a Context and then the SharedPreference reference using the PreferenceManager class. Then, we will create an instance of a List of notes for adding the notes after fetching it. We use the Map type for looping through the saved data inside SharedPreference. We will add all the data to the list inside the loop; it returns the noteList:
public static List<Note> getAllNotes(Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); List<Note> noteList = new ArrayList<>(); Map<String, ?> key = sharedPreferences.getAll(); for (Map.Entry<String, ?> entry : key.entrySet()) { String savedValue = (String) entry.getValue(); if (savedValue != null) { Note note = new Note(entry.getKey(), savedValue); noteList.add(note); } } return noteList; }
推薦閱讀
- 零基礎(chǔ)學(xué)Visual C++第3版
- 流量的秘密:Google Analytics網(wǎng)站分析與優(yōu)化技巧(第2版)
- Debian 7:System Administration Best Practices
- CentOS 7 Linux Server Cookbook(Second Edition)
- Apache Spark 2 for Beginners
- Responsive Web Design with HTML5 and CSS3
- 你必須知道的204個(gè)Visual C++開發(fā)問題
- PHP+MySQL+Dreamweaver動態(tài)網(wǎng)站開發(fā)實(shí)例教程
- Unity 5.x By Example
- Hands-On Microservices with Kotlin
- H5頁面設(shè)計(jì):Mugeda版(微課版)
- Visual Foxpro 9.0數(shù)據(jù)庫程序設(shè)計(jì)教程
- Instant PHP Web Scraping
- 零基礎(chǔ)學(xué)C語言(升級版)
- PhoneGap 4 Mobile Application Development Cookbook