Photo by Jan Mellström on Unsplash

So, you may be trying to set up a RecyclerView that has different ViewHolders. For instance, a Post object that could have a picture or might be just text with different ViewHolders for each case.

While the code in the guide covers that scenario, we are going to take it a step further and also tackle a slightly different problem. Our goal is to add objects of different types to a single RecyclerView in a simple to implement and easy to manage way.

The Problem:

We have three objects: Book, Magazine, and Newspaper. We want to display them in one…


photo by Magda Ehlers

Swipe to delete is a prevailing paradigm users are accustomed to on mobile platforms. Adding this functionally is a good way to get your app in line with modern design practices. While there are many libraries that will accomplish this for us, subsequently adding extra bulk to our code, implementing it ourselves is not that complicated. So, let’s get started.

To implement swipe to delete and undo in our RecyclerView we are going to need 3 key components:

  1. ItemTouchHelper: This attaches to the RecyclerView and watches for swipes.
  2. ItemTouchHelper.SimpleCallback: This is passed into ItemTouchHelper’s constructor and contains the code that…

Zachery Osborn

Android developer

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