---
title: "Notify Item Removed Safely"
date: 2017-05-22T12:17:54.000Z
author: Z.SHINCHVEN
tags: [RecyclerView, Android]
canonical: https://atlassc.net/2017/05/23/notify-item-removed-safely
---
RecyclerView's adapter provides more powerful methods for developers to animate their list like you can easily run a remove animation on one particular item in the list by calling `adapter.notifyItemRemoved(position)`.

But you must be careful with the `position` when you removed the one last item in your list, for there won't be any item left in your list to be animated, you might just get an `java.lang.IndexOutOfBoundsException` instead of an animation.

So in my case, I use `adapter.notifyItemRemoved(position)` only when there are items left in my list like:

```Java
if (list.size() > 0) {
    adapter.notifyItemRemoved(position); // animate removing when there are items left in the list.
} else {
    adapter.notifyDataSetChanged(); // refresh the whole list there is no item left in the list.
}
```
