Click to Open Details
Discover how to add a click listener to the list item in this lesson.
We'll cover the following
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) -
Retrieve the Bundle object from the Intent via the
extras
property (object which contains some data carried by Intent) -
Retrieve the
Blog
object from the Bundle via thegetParcelable
method passing the String key as a parameter
Get hands-on with 1400+ tech skills courses.