Recycler Viewer in Kotlin


Recycler Viewer in Kotlin

Recycler viewer is the advanced version of ListView for better performance. When you have a list of long items to show you can be recycled. There is the ability to reuse its views. The view will not destroy the viewing from the screen or not be visible to the user. This feature helps to reduce power consumption and adds more responsiveness.

Implementation of Recycler View

  1. Creating a new project
    • To create a new Android Studio Project using Kotlin first.
    • Remove ACTIVITY_MAIN.XML when the project is loaded, and remove Hello World TextView.
  2. Adding recycler view
    • Now search for RecyclerView and drag it to your activity_main.xml.
    • When you drag RecyclerView, it will ask you to add the RecyclerView dependency.
  3. To Create List Layout using CardView.
    • Now for the list items, we will create a new layout. To create a new layout resource file and name it list_layout.xml.
    • Go to the same search CardView and drag it to the layout you just created. It will again ask you to add CardView dependency.
  4. Creating Model
    • The list is about a user, so that we will create a User class.
  5. Creating RecyclerView Adapter
    • We need an Adapter to display the data in RecyclerView.