Click to Open Details

Discover how to add a click listener to the list item in this lesson.

Details screen changes

The very first thing we need to do is update the details screen. Instead of loading blog details again, we can just pass the data from the MainActivity to the BlogDetailsActivity via the intent bundle.

First let’s add a companion object with an EXTRAS_BLOG constant. In Kotlin a companion object is used to declare constants in the class or functions which don’t require instances of the object.

To learn more about delegate properties navigate to Kotlin documentation.

Next, let’s remove the loadData method and instead, call the showData method. To get Blog from the parameter we need to:

  • Acquire a reference to the Intent object via the intent property (object which was used to launch this Activity) ...