{"id":4623,"date":"2019-05-17T10:00:36","date_gmt":"2019-05-17T04:30:36","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=4623"},"modified":"2026-10-26T17:08:18","modified_gmt":"2026-10-26T11:38:18","slug":"how-to-implement-recycler-view-in-android","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/how-to-implement-recycler-view-in-android\/","title":{"rendered":"How to Implement RecyclerView in Android: A Step-by-Step Guide"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Post Date:<\/strong> May 16, 2019<br><strong>Last Updated:<\/strong> October 26, 2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>RecyclerView<\/code> is an Android UI component used to display large datasets efficiently in a scrollable list or grid. It is a more flexible alternative to the older <code>ListView<\/code> component and supports different layouts, animations, and item decorations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">RecyclerView uses several components to display data:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>RecyclerView:<\/strong> The main container that displays the list or grid.<\/li>\n\n\n\n<li><strong>Adapter:<\/strong> Connects the dataset to the RecyclerView and creates item views.<\/li>\n\n\n\n<li><strong>ViewHolder:<\/strong> Holds references to the views used to display an individual item.<\/li>\n\n\n\n<li><strong>LayoutManager:<\/strong> Controls how items are arranged, such as vertically, horizontally, or in a grid.<\/li>\n\n\n\n<li><strong>ItemDecoration:<\/strong> Adds visual enhancements, such as spacing or dividers between items.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">When an item scrolls off-screen, RecyclerView can reuse its view to display another item. This reduces unnecessary view creation and helps improve performance.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains how to implement a basic RecyclerView in an Android application using Kotlin and XML layouts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before implementing RecyclerView, ensure you have:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.android.com\/studio\" data-type=\"link\" data-id=\"https:\/\/developer.android.com\/studio\" target=\"_blank\" rel=\"noopener\">Android Studio<\/a> installed.<\/li>\n\n\n\n<li>A basic understanding of Kotlin and Android development.<\/li>\n\n\n\n<li>An Android project configured to use XML layouts.<\/li>\n\n\n\n<li>The AndroidX RecyclerView dependency added to your application.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Reference Article: <a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-install-android-studio\/\">How to Install Android Studio on Windows and macOS<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Add the RecyclerView Dependency<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open your app-level Gradle file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For projects using Kotlin DSL (<code>build.gradle.kts<\/code>), add the following dependency inside the <code>dependencies<\/code> block:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">implementation(\"androidx.recyclerview:recyclerview:1.4.0\")<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For projects using Groovy (<code>build.gradle<\/code>), use:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">implementation 'androidx.recyclerview:recyclerview:1.4.0'<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Sync your project with Gradle after adding the dependency.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> The version shown is an example. Check the official Android documentation for the latest stable version compatible with your project&#8217;s Android Gradle Plugin and SDK configuration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Add RecyclerView to the Layout File<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open <code>activity_main.xml<\/code> and add the RecyclerView component.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?>\n&lt;androidx.recyclerview.widget.RecyclerView\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:id=\"@+id\/recyclerView\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:padding=\"16dp\"\n    android:clipToPadding=\"false\" \/><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This creates a RecyclerView that occupies the available screen space.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A LayoutManager must be assigned before the RecyclerView can arrange its items.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Create a Layout for Individual Items<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new layout file named <code>item_name.xml<\/code> inside the <code>res\/layout<\/code> directory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This layout defines how each item appears in the list.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?>\n&lt;LinearLayout\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\"\n    android:orientation=\"vertical\"\n    android:padding=\"16dp\">\n\n    &lt;TextView\n        android:id=\"@+id\/txtName\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:textSize=\"18sp\"\n        android:textColor=\"#212121\" \/>\n\n&lt;\/LinearLayout><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>TextView<\/code> displays the data associated with each item. You can customize this layout to include images, buttons, or additional text fields.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Create the RecyclerView Adapter<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The adapter connects the dataset to the RecyclerView. It creates item views, stores their view references, and binds data to them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a Kotlin class named <code>NameAdapter.kt<\/code>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import android.view.LayoutInflater\nimport android.view.View\nimport android.view.ViewGroup\nimport android.widget.TextView\nimport androidx.recyclerview.widget.RecyclerView\n\nclass NameAdapter(\n    private val names: List&lt;String>\n) : RecyclerView.Adapter&lt;NameAdapter.NameViewHolder>() {\n\n    class NameViewHolder(itemView: View) :\n        RecyclerView.ViewHolder(itemView) {\n\n        val nameTextView: TextView =\n            itemView.findViewById(R.id.txtName)\n    }\n\n    override fun onCreateViewHolder(\n        parent: ViewGroup,\n        viewType: Int\n    ): NameViewHolder {\n\n        val view = LayoutInflater.from(parent.context)\n            .inflate(R.layout.item_name, parent, false)\n\n        return NameViewHolder(view)\n    }\n\n    override fun onBindViewHolder(\n        holder: NameViewHolder,\n        position: Int\n    ) {\n        holder.nameTextView.text = names[position]\n    }\n\n    override fun getItemCount(): Int = names.size\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The adapter includes three essential methods:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>onCreateViewHolder()<\/strong><\/code> creates the layout for an individual list item.<\/li>\n\n\n\n<li><code><strong>onBindViewHolder()<\/strong><\/code> binds the appropriate data to the item at the specified position.<\/li>\n\n\n\n<li><code><strong>getItemCount()<\/strong><\/code> returns the total number of items in the dataset.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>NameViewHolder<\/code> class stores references to the views used by each item.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Configure RecyclerView in the Activity<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open <code>MainActivity.kt<\/code> and initialize the RecyclerView with a LayoutManager and the adapter.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import android.os.Bundle\nimport androidx.appcompat.app.AppCompatActivity\nimport androidx.recyclerview.widget.LinearLayoutManager\nimport androidx.recyclerview.widget.RecyclerView\n\nclass MainActivity : AppCompatActivity() {\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContentView(R.layout.activity_main)\n\n        val recyclerView =\n            findViewById&lt;RecyclerView>(R.id.recyclerView)\n\n        val names = listOf(\n            \"Arun\",\n            \"Priya\",\n            \"Kumar\",\n            \"Meena\",\n            \"Ravi\"\n        )\n\n        recyclerView.layoutManager =\n            LinearLayoutManager(this)\n\n        recyclerView.adapter = NameAdapter(names)\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>LinearLayoutManager<\/code> arranges the items vertically by default.<\/li>\n\n\n\n<li><code>NameAdapter<\/code> provides the names to display.<\/li>\n\n\n\n<li>The RecyclerView displays each name using the <code>item_name.xml<\/code> layout.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Important:<\/strong> This example assumes your project already includes the AndroidX AppCompat dependency. If your project does not use <code>AppCompatActivity<\/code>, you can use an appropriate activity class supported by your project.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Run and Test the Application<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Build and run the application in an Android emulator or on a connected device.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Verify that:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>The list of names appears on the screen.<\/li>\n\n\n\n<li>Each name is displayed in its own item view.<\/li>\n\n\n\n<li>The list scrolls correctly when the dataset exceeds the visible screen area.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">If the RecyclerView does not display any items, verify the layout IDs, adapter initialization, dataset, and LayoutManager configuration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 7: Customize the RecyclerView<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">RecyclerView supports different layouts and visual enhancements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Display items in a grid:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">recyclerView.layoutManager =\n    androidx.recyclerview.widget.GridLayoutManager(this, 2)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This arranges items in two columns.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Add spacing or dividers:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can implement a custom <code>RecyclerView.ItemDecoration<\/code> to add spacing or dividers between items.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Handle item clicks:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can define a callback or listener in the adapter to notify the activity or fragment when a user selects an item.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These options allow you to adapt RecyclerView to different application requirements.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">RecyclerView provides an efficient and flexible way to display lists and grids in Android applications. By configuring a RecyclerView, creating an item layout, implementing an adapter and ViewHolder, and assigning a LayoutManager, you can build a reusable list component.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can extend this implementation with click listeners, custom item decorations, multiple view types, and more advanced data-handling techniques as your application grows.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently Asked Questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. What is RecyclerView in Android?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">RecyclerView is a UI component used to display scrollable collections of items efficiently by reusing item views.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. What is the purpose of a ViewHolder?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A ViewHolder stores references to the views within an item. This allows the adapter to access and update those views when binding data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. What is the difference between RecyclerView and ListView?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">RecyclerView provides a more flexible architecture with dedicated adapters, ViewHolders, LayoutManagers, item decorations, and animation support.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Why is a LayoutManager required?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The LayoutManager determines how items are positioned and arranged within the RecyclerView. Common options include <code>LinearLayoutManager<\/code>, <code>GridLayoutManager<\/code>, and <code>StaggeredGridLayoutManager<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. Can RecyclerView display different types of items?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. You can override <code>getItemViewType()<\/code> and implement the appropriate ViewHolder and binding logic to display different item layouts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related Articles<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/first-android-studio-project\/\">How to Create First project in Android Studio.<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-add-a-project-on-android-studio-from-github\/\">How to Import a Project from GitHub into Android Studio<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pheonixsolutions.com\/blog\/how-to-create-a-project-and-overflow-menu-on-your-application-in-android-studio\/\">How to Create a Project and an Overflow Menu in Android Studio<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Need Assistance?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you need assistance implementing RecyclerView or troubleshooting your Android application, please contact the <a href=\"https:\/\/pheonixsolutions.com\/\" data-type=\"link\" data-id=\"https:\/\/pheonixsolutions.com\/\">Pheonix Solutions<\/a> support team. Include a description of the issue and any relevant error messages or code snippets so our team can investigate and assist you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For further assistance, please <a href=\"https:\/\/pheonixsolutions.com\/contact\/\" data-type=\"link\" data-id=\"https:\/\/pheonixsolutions.com\/contact\/\">contact our support team<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Post Date: May 16, 2019Last Updated: October 26, 2026 Introduction RecyclerView is an Android UI component used to display large [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1021],"tags":[569,651,566],"class_list":["post-4623","post","type-post","status-publish","format-standard","hentry","category-mobile-flutter","tag-android","tag-recyclerview","tag-ui","psol-cat-mobile-flutter"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1cz","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=4623"}],"version-history":[{"count":1,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4623\/revisions"}],"predecessor-version":[{"id":12498,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4623\/revisions\/12498"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=4623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=4623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=4623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}