https://unsplash.com/photos/DJ7bWa-Gwks

When creating RecyclerView lists, we usually encounter list items that have the same ViewHolder but the values inside it are subject to different conditions.

Let’s say we’re building a list that displays invoices in a card view. Each item in the list has these conditions:

For unpaid invoice:

  1. Displays “Unpaid” label at the top right corner of the card view
  2. Displays “Pay” button at the bottom of the card view
  3. Displays due date in “dd-MM-yyyy” format

For paid invoice:

  1. Displays “Paid” label at the top right corner of the card view
  2. Displays “View” button at the bottom of the card…


https://unsplash.com/photos/t6Wmvbw_MdI

Through the years of developing Android apps, there have been countless times that we implemented simple lists. Lists that only have these basic features:

  1. Display items
  2. Handle item clicks

Using ListAdapter and with the help of DataBinding, we can create a powerful and reusable SimpleListAdapter which we can use every time we implement a simple list.

I’ll share a step by step tutorial in this article on how to achieve this.

Enough of the introduction and let’s get our hands dirty!

  1. Let’s create our item layout. For this one, let’s assume we will display a list of news articles. …


It’s more than just comparing item ids.

Photo by Dayne Topkin on Unsplash

Often, I see some new developers who are using DiffUtil.ItemCallback class the wrong way. Like this:

fun areItemsTheSame(oldItem: Item, newItem: Item): Boolean {
return oldItem.id == newItem.id
}
fun areContentsTheSame(oldItem: Item, newItem: Item): Boolean {
return oldItem.id == newItem.id
}

Surely, this will work just fine if you display your list once and NEVER update it again.

But, what if you start updating the list? Let’s say you have a refresh function. This is when the wrong implementation hits you.

You will be stuck on calling adapter.submitList(newList) and seeing your list not updating…


https://unsplash.com/photos/zNRITe8NPqY

Hi! I’m writing this short blog to share a simple problem that I encountered while implementing Paging 3 in one of my projects.

Let’s get started!

Problem

Let’s say we are developing a Notifications screen that requires pagination. Our item has 2 states, read and unread state. Currently, you can’t update an item directly from PagingData as exposed by the Paging 3 library.

Workaround

As a simple workaround, we can make the read state inside our Notification object mutable like this:

data class Notification(
val id: Int,
var read: Boolean <-- Emphasis on the "var"
...
)

With this setup, we can…


https://unsplash.com/photos/9rClrXXi7ys

Problem

Have you ever encountered scrolling to the bottom of a RecyclerView and the last item looks too close to the bottom of the screen?

It looks awkward. It would be good if we can add a margin after the last item to give it a more breathing room. But how?

Possible solution

One solution could be adding a Footer item type with a fixed height to your adapter.

But, this has a few major drawbacks. First, you will have to change the data set to include the footer item. Appending new items to the list is now a headache since you…

Jermaine Dilao

A Work in Progress Android Developer. You can check me at https://jermainedilao.github.io/.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store