Displaying Data From Code
Explore how to load and display blog data from code by implementing RecyclerView with ListAdapter and DiffUtil in Kotlin. Learn to optimize list rendering through view holders and binding, and connect your data adapter within MainActivity to present a dynamic list screen.
We'll cover the following...
Loading data from the Internet
During the previous lessons, we created a BlogHttpClient that loads a list of blog articles. Let’s modify our code to support the new JSON format.
Old JSON format:
The main changes in the new JSON format are:
- We have an
idattribute - The
imageandavatarnow contain a relative path
In the BlogHttpClient, we need to change the URL to the following:
This gives us the ability to concatenate the BASE_URL with the relative path of the blog image or the author avatar. Let’s add additional get methods to the Author class and the Blog class which are going to return full image URLs.
Now, we can modify the MainActivity code and add a blog loading code similar to what we have in BlogDetailsActivity.
List Adapter
In order for RecyclerView to render and reuse the list of items, we need to use one of the implementations of the ...