- 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; }
推薦閱讀
- C++ Primer習題集(第5版)
- WildFly:New Features
- 兩周自制腳本語言
- OpenStack Cloud Computing Cookbook(Fourth Edition)
- Linux網絡程序設計:基于龍芯平臺
- WordPress Plugin Development Cookbook(Second Edition)
- 從學徒到高手:汽車電路識圖、故障檢測與維修技能全圖解
- Go并發編程實戰
- 深入理解Elasticsearch(原書第3版)
- R用戶Python學習指南:數據科學方法
- 精通MySQL 8(視頻教學版)
- 大數據時代的企業升級之道(全3冊)
- C# 7 and .NET Core 2.0 Blueprints
- 系統分析師UML用例實戰
- Java EE框架開發技術與案例教程