- 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; }
推薦閱讀
- LaTeX Cookbook
- JavaScript百煉成仙
- 數據庫系統教程(第2版)
- Spring Cloud Alibaba微服務架構設計與開發實戰
- Game Programming Using Qt Beginner's Guide
- Visual FoxPro程序設計教程
- Mastering phpMyAdmin 3.4 for Effective MySQL Management
- Bulma必知必會
- SSM輕量級框架應用實戰
- Web Development with MongoDB and Node(Third Edition)
- 大數據分析與應用實戰:統計機器學習之數據導向編程
- Mastering openFrameworks:Creative Coding Demystified
- C#程序設計教程(第3版)
- 區塊鏈項目開發指南
- OpenCV Android Programming By Example