# Suspending over Views -- Example

DevFeed: [Suspending over Views -- Example](<https://devfeed.tech/articles/suspending-over-views-example-24928.md>)

Original publisher: [Read original article](<https://medium.com/androiddevelopers/suspending-over-views-example-260ce3dc9100?source=rss-9303277cb6db------2>)

Author: Chris Banes

Published: 2019-12-02T08:57:37Z

Content type: tutorial

Language: en

Sources: [Chris Banes on Medium](<https://devfeed.tech/sources/chris-banes-on-medium.md>)

Topics: [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [recyclerview](<https://devfeed.tech/topics/recyclerview.md>), [ui](<https://devfeed.tech/topics/ui.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [asynchronous](<https://devfeed.tech/tags/asynchronous.md>), [callback](<https://devfeed.tech/tags/callback.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [development](<https://devfeed.tech/tags/development.md>), [kotlin-coroutines](<https://devfeed.tech/tags/kotlin-coroutines.md>), [recyclerview](<https://devfeed.tech/tags/recyclerview.md>), [ui](<https://devfeed.tech/tags/ui.md>)

## AI overview

A worked example from the Tivi app shows how coroutines can simplify asynchronous UI operations. It examines a broken episode-expanding animation caused by reused item IDs and views that may not be attached to the RecyclerView.

## Source excerpt

Illustration by Virginia PoltrackSuspending over views -- exampleA worked example from the Tivi app This blog post is the second of two which explores how coroutines enables you to write complex asynchronous UI operations in a much simpler way. The first post goes through the theory, while this post demonstrates how they fix a problem. If you want to recap the first post, you can find it here: Suspending over Views Let's take what we learnt in the previous post and apply it to a real-world app use case. The problem Here we have the TV show details UI from the Tivi sample app. As well as information about the show, it lists the show's seasons and episodes. When the user clicks one of the episodes, the episode's details are displayed using an animation which expands the clicked item: Episode expanding (20% speed) The app uses the InboxRecyclerView library to handle the expanding animation above: https://medium.com/media/af84b36b2b481525fbab682b6a6cffa7/href InboxRecyclerView works by us providing the item ID of view to expand. It then finds the matching view from the RecyclerView items, and performs the animation on it. Now let's look at the issue we're trying to fix. Near the top of the same UI is a different item, which shows the user their next episode to watch. It uses the same view type as the individual episode item shown above, but has a different item ID. To aid development, I was lazy and used the same onEpisodeItemClicked() for this item. Unfortunately this led to a broken animation when clicked. Wrong item expanding (20% speed) Instead of expanding the clicked item, the library expands a seemingly random item at the top. This is not the effect we want, and is caused by some underlying issues: The ID we use in the click listener is taken directly from the Episode class. This ID maps to the individual episode item within the season list. The episode item may not be attached to the RecyclerView. The user would need to have expanded the season and scrolled so th