Hello everyone, in this post I will share a simple tutorial for those of you who are just learning to make android applications using android studio.
In this tutorial we will learn to create a recyclerview in android studio.
1. Create New Project
The first thing we have to do is of course create a new project in android studio. In this tutorial I named the project "Recyclerview".
2. Adding permissions in Manifest
Open AndroidManifest.xml then add internet permissions so that the application can access the internet. This is required so that images loaded from urls can be displayed.
3. Added dependencies in Gradle
Add recyclerview, cardview and glide libraries.
4. Create class data
This data class is used to store data
5. Desain user interface
Open activity_main.xml, then add recyclerview as follows
Create a new layout with the name item_list.xml for each item's view. This is where we put the cardview. In this example we display the image, title and post date of the article.
6. Making adapters
Here is the complete code for the adapter for recyclerview. In this adapter we also add an action when the item is clicked, it will open the selected article.
7. Prepare data
Here I prepare dummy data in the form of ArrayList
8. Showing data in recyclerview
To display the data, we just need to send the data to the adapter with the addItems function and don't forget to add notifyDataSetChanged() to refresh our recyclerview.
9. MainActivity.kt full code
Here is the complete code for MainActivity.kt