Android RecyclerView Tutorial with Kotlin | raywenderlich.com

In this Android RecyclerView tutorial, learn how to use Kotlin to display datasets of a large or unknown size!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1560485-android-recyclerview-tutorial-with-kotlin

Thank you for this tutorial. I believe arrayListOf is the more Kotlin way of declaring the list of Photo objs, rather than ArrayList<Photo> like you recommended.

Thank you for that. You are correct.

Hey ! Your tutorial was really awesome. I loved it but I am having a bit of a problem, When I compile my project, it shows unresolved reference : PhotoHolder. Please help.
Thank you!

Could you give me more information on which version of Android Studio you are using and the exact error message you are seeing?

When running outside USA, the date string will be rejected as it will be out of current acceptable range from NASA server. TimeZone has to be added:

private val calendar: Calendar = Calendar.getInstance(TimeZone.getTimeZone(ā€œAmerica/New_Yorkā€))

and dateFormat has to be set to use its time zone in init:

dateFormat.setCalendar(calendar)

Thanks for letting us know!

Hey guys,
In my honest opinion, despite this is a good use case for a real world app, I think it is over complicated for introducing a beginners topic.

Why choose to include networking with API, parsing JSON, etc in a tutorial specific for RecyclerView tutorial?
The data could have been in a local storage and the project could have been much smaller and simpler (by choosing a different kind of data to showcase, like pets)

Using the network calls gives us data to show and since the user doesnā€™t need to know how to use the API code (itā€™s already there for them), it can just provide a reference for them if they are interested.

I agree with ofir-bar.

I am trying to learn just RecyclerView. I donā€™t want to sign up with another site to get some API keys. I donā€™t want to deal with other technologies.

I have the beginning of an app. Iā€™ve collected all the data via web-scraping. Got it all in an ArrayList (Match is my class). I just want to display it in a List with Section headers. As far as I can tell, Android doesnā€™t have the concept of Sections or Section headers in a ListView or RecycleView. That I can work around, butā€¦

I just want to display my data in a RecyclerView. Why canā€™t I find a tutorial that tells me just that?

I have been looking all over the internet for three weeks to find a Quick-and-Dirty RecyclerView tutorial. Iā€™m not very impressed with any Android/Kotlin tutorials/resources out there. They are way too complicated or incomplete.

Could you copy the recyclerview class and adapter code and use just an array of your data? I would recommend starting your project and slowly build in the recyclerview class using parts of the code from the tutorial. There were lots of articles on the basics of recyclerviews out there and I wanted to add a bit more information for the adventurous (something the user would have to do a lot of different searches for). When Iā€™m learning something new, I usually start with just the basic code outline and slowly add more code. I hope that helps.

Nice tutorial, there is a part might be a typo
ā€œNext, in receivedNewPhoto(), add the following after photosList.add:
adapter.notifyItemInserted(photosList.size)ā€

And next how it should show in code is:
adapter.notifyItemInserted(photosList.size-1)

Is that -1 needed?

Good catch. It should be -1 in both places. Since lists are 0 based, the last item will be size-1

Reading this article again in April, Iā€™m able to follow it better, but Iā€™ve found some typos:

  1. In the code snippet that adds the photos variable, just before ā€œNice job, Commander!ā€, I believe there is a missing colon.

  2. In the text just before the next code snippet, I believe the start of the last sentence should be changed from ā€œAdd update getItemCount()ā€¦ā€ to just: ā€œUpdate getItemCount()ā€¦ā€

  3. In the section, ā€œKeeping Hold of Your Viewsā€, the last line before the code snippet states: ā€œAdd the following code at the bottom of the RecyclerAdapter class:ā€ When I first copied/pasted it, I put it outside the RecyclerAdapter class, which didnā€™t work. You might want to change your text to be more specific, like ā€œjust before the last trailing ā€˜}ā€™ā€ oslt.

Hi Kevin,

I completed this tutorial and eagerly moved on to the intermediate tutorial, because Iā€™m trying to get section headers, like the iOS grouped TableViews. (Canā€™t believe itā€™s not built-in in Android Studio!)

But, the intermediate tutorial is completely different project, which means you canā€™t build on this project to add new features. Even trying to sift through the tutorial and apply the new elements found there to this project doesnā€™t work so well because the projects are so different, even when comparing similar methods.

This tutorial was updated at some point. Is there any chance that the other one could be updated, too? Or another one that truly follows this one?

Iā€™m really struggling to add these section headersā€¦

Hi - Iā€™m a Kotlin NOOB and Iā€™m trying to follow the tutorial.
TravelListAdapter.kt is giving many errors all related to the ViewHolder inner class

   inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), 
        View.OnClickListener {
    }

which gives the following error:

Class 'ViewHolder' is not abstract and does not implement abstract member*      
    public abstract fun  onClick(pO:  View!):  Unit defined in *
   android.view.View.OnClickListener*

Please help.
Thanks
Elliot

You have to implement all of the functions of RecyclerView.ViewHolder. Usually you will see a red line underneath the ViewHolder class. If you click on ViewHolder you should see a red icon popup with a suggestion to implement that interface. Implement all functions.

I really enjoyed this space travel. Loved this tutorial so much. Thank you to all the creative team <3

@cynthialove Really glad you like it! Cheers! :]

@zonker Do you still have issues with this?