From the course: Android Development Essential Training: Manage Data with Kotlin
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Use preferences to manage display
From the course: Android Development Essential Training: Manage Data with Kotlin
Use preferences to manage display
- [Instructor] I've added the code I need to set and get preferences programmatically and I also have a new layout file that I'll use to display my data in a list. Now I'll put it all together by writing to that preference and then reading from it a couple of time. I'll start in the main fragment. In this class I've added code to display an options menu. That's how those icons are appearing on the toolbar. And then when the user selects one of those items it'll trigger the function on option items selected and I have cases already in place for selecting a grid or a list. In the first option I'll use my prefs helper class and call it set item type function. I'll pass in requireContext as the context, and then a string of grid. You could also use a constant for this. Now I want to override the recylerView's layout manager. I'll call recyclreView.layoutManager equals GridLayoutManager and I'll pass in the context again and then a value of two for the span count and that will make sure…