Skip to content

Android RecyclerView in Kotlin

Android RecyclerView in Kotlin is one of the most interesting concepts to become a master in Android. There are a lot of different examples and implementations across the internet. Learn first, what a RecyclerView is before implementing it.

If you are interested in becoming a professional software developer, make sure to check out our courses!

[fusion_builder_container hundred_percent=”no” hundred_percent_height=”no” hundred_percent_height_scroll=”no” hundred_percent_height_center_content=”yes” equal_height_columns=”no” menu_anchor=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” status=”published” publish_date=”” class=”” id=”” link_color=”” link_hover_color=”” border_size=”” border_color=”” border_style=”solid” margin_top=”” margin_bottom=”” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” gradient_start_color=”” gradient_end_color=”” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_color=”” background_image=”” background_position=”center center” background_repeat=”no-repeat” fade=”no” background_parallax=”none” enable_mobile=”no” parallax_speed=”0.3″ background_blend_mode=”none” video_mp4=”” video_webm=”” video_ogv=”” video_url=”” video_aspect_ratio=”16:9″ video_loop=”yes” video_mute=”yes” video_preview_image=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″][fusion_builder_row][fusion_builder_column type=”1_1″ layout=”1_1″ spacing=”” center_content=”no” link=”” target=”_self” min_height=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” hover_type=”none” border_size=”0″ border_color=”” border_style=”solid” border_position=”all” box_shadow=”no” box_shadow_blur=”0″ box_shadow_spread=”0″ box_shadow_color=”” box_shadow_style=”” background_type=”single” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_color=”” background_image=”” background_image_id=”” background_position=”left top” background_repeat=”no-repeat” background_blend_mode=”none” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” filter_type=”regular” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″ first=”true” last=”true”][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” rotation_text=”” highlight_text=”” after_text=”” content_align=”left” size=”2″ font_size=”30″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Working with RecyclerView in Kotlin

[/fusion_title][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=””]

RecyclerViews in Android is one of the most interesting concepts to become a master in Android. There are a lot of different examples and implementations across the internet. Learn first, what a RecyclerView is before implementing it.

[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”2″ font_size=”30″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]What is a RecyclerView?

[/fusion_title][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

A RecyclerView is a flexible view for providing a limited window into a large data set. It is essentially a ViewGroup of containers called ViewHolders which populate a particular item. RecyclerView is an extensive Android class to provide a flexible UI. A great benefit of using RecyclerViews is that you’re able to efficiently reuse views instead of managing items that aren’t even visible to a user.

[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”2″ font_size=”30″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]Why we use RecyclerView? [/fusion_title][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=””]

In the past, Android was using ListView or GridView classes for displaying lists. The RecyclerView can be described as a combination of a ListView and a GridView. However, in a RecyclerView, there are features that separate your code into maintainable components while also enforcing memory-efficient design patterns.

The form you have selected does not exist.

How is it better than ListViews and GridViews?

ListViews and GridViews are comparatively slower than RecyclerViews.

[/fusion_text][fusion_imageframe image_id=”4262|full” max_width=”1024″ style_type=”” blur=”” stylecolor=”” hover_type=”none” bordersize=”” bordercolor=”” borderradius=”” align=”center” lightbox=”no” gallery_id=”” lightbox_image=”” lightbox_image_id=”” alt=”” link=”” linktarget=”_self” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″]https://tutorials.eu/wp-content/uploads/2020/07/RecycleViewApp.png[/fusion_imageframe][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”2″ font_size=”30″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]Layouts in RecyclerView[/fusion_title][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=””]

The RecyclerView changed everything which was used in the ListView and GridView. RecyclerView still uses an Adapter to act as a data source. However, you have to create ViewHolders to keep references in memory.

To provide a new view, RecyclerView either creates a new ViewHolder object to inflate the layout and hold those references, or it recycles one from the existing stack.

This is it why it’s called a RecyclerView!

The Views in RecyclerView comes with default animations that you don’t have to create or add yourself.

RecyclerView requires a ViewHolder, the RecyclerView knows which animation to apply to which item and adds them as required. You can also create your own animations and apply them as needed.

The most important and interesting component of a RecyclerView is its LayoutManager. This object positions the RecyclerView’s items and tells them when to recycle items that have transitioned off-screen. The ListView used to do this work by itself.

The RecyclerView has broken out of this functionality to allow for different kinds of layouts: Vertical, Horizontal, Grid, Staggered, or your own!

There are three types of Layout Managers by default:

  1. LinearLayoutManager: Positions items to look like a standard ListView.
  2. GridLayoutManager: Positions items in a grid format similar to a GridView.
  3. StaggeredGridLayoutManager: Positions terms in a staggered grid format.

RecyclerView implementations requires:

  1. A list of data objects to work with.
  2. An XML file of the view item.
  3. An adapter to bind that data to the views.
  4. A ViewHolder to populate the UI view from the XML item file.

The form you have selected does not exist.

Now we are familiar with what RecyclerView is and its basics, let’s get into the implementation.

[/fusion_text][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container][fusion_builder_container hundred_percent=”no” hundred_percent_height=”no” hundred_percent_height_scroll=”no” hundred_percent_height_center_content=”yes” equal_height_columns=”no” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” status=”published” border_style=”solid” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_position=”center center” background_repeat=”no-repeat” fade=”no” background_parallax=”none” enable_mobile=”no” parallax_speed=”0.3″ background_blend_mode=”none” video_aspect_ratio=”16:9″ video_loop=”yes” video_mute=”yes” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″][fusion_builder_row][fusion_builder_column type=”1_1″ layout=”1_1″ center_content=”no” target=”_self” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” hover_type=”none” border_size=”0″ border_style=”solid” border_position=”all” box_shadow=”no” box_shadow_blur=”0″ box_shadow_spread=”0″ background_type=”single” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_position=”left top” background_repeat=”no-repeat” background_blend_mode=”none” animation_direction=”left” animation_speed=”0.3″ filter_type=”regular” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″ first=”true” last=”true” min_height=”” link=””][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”2″ font_size=”30″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]Get started with RecyclerView[/fusion_title][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Create a New Project for this RecyclerViews tutorial

[/fusion_title][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]Create a new Android Studio project using Kotlin.

[/fusion_text][fusion_imageframe image_id=”4165|fusion-600″ max_width=”1000″ style_type=”” blur=”” stylecolor=”” hover_type=”none” bordersize=”3″ bordercolor=”” borderradius=”” align=”center” lightbox=”no” gallery_id=”” lightbox_image=”” lightbox_image_id=”” alt=”” link=”” linktarget=”_self” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″]https://tutorials.eu/wp-content/uploads/2020/07/1-600×444.jpg[/fusion_imageframe][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]Select option as Start a new Android Studio project.

[/fusion_text][fusion_imageframe image_id=”4169|fusion-600″ max_width=”” style_type=”” blur=”” stylecolor=”” hover_type=”none” bordersize=”” bordercolor=”” borderradius=”” align=”center” lightbox=”no” gallery_id=”” lightbox_image=”” lightbox_image_id=”” alt=”” link=”” linktarget=”_self” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″]https://tutorials.eu/wp-content/uploads/2020/07/2-600×429.jpg[/fusion_imageframe][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]Select Empty Activity and click on Next.

[/fusion_text][fusion_imageframe image_id=”4170|fusion-600″ max_width=”” style_type=”” blur=”” stylecolor=”” hover_type=”none” bordersize=”” bordercolor=”” borderradius=”” align=”center” lightbox=”no” gallery_id=”” lightbox_image=”” lightbox_image_id=”” alt=”” link=”” linktarget=”_self” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″]https://tutorials.eu/wp-content/uploads/2020/07/3-600×428.jpg[/fusion_imageframe][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

 

Add the name of the project as RecyclerViewApp and update the package name as you want and select the project location where you want to save the project.

Create a project using Kotlin.

Once the project is loaded go inside the activity_main.xml and remove the Hello World TextView.

Add the dependency in the build.gradle (:app) :

implementation ‘com.google.android.material:material:1.1.0’

[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]Add the RecyclerView[/fusion_title][fusion_code]PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPGFuZHJvaWR4LmNvbnN0cmFpbnRsYXlvdXQud2lkZ2V0LkNvbnN0cmFpbnRMYXlvdXQgeG1sbnM6YW5kcm9pZD0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vYXBrL3Jlcy9hbmRyb2lkIgogICAgeG1sbnM6YXBwPSJodHRwOi8vc2NoZW1hcy5hbmRyb2lkLmNvbS9hcGsvcmVzLWF1dG8iCiAgICB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiCiAgICBhbmRyb2lkOmxheW91dF93aWR0aD0ibWF0Y2hfcGFyZW50IgogICAgYW5kcm9pZDpsYXlvdXRfaGVpZ2h0PSJtYXRjaF9wYXJlbnQiCiAgICB0b29sczpjb250ZXh0PSIuTWFpbkFjdGl2aXR5Ij4KCiAgICA8YW5kcm9pZHgucmVjeWNsZXJ2aWV3LndpZGdldC5SZWN5Y2xlclZpZXcKICAgICAgICBhbmRyb2lkOmxheW91dF93aWR0aD0ibWF0Y2hfcGFyZW50IgogICAgICAgIGFuZHJvaWQ6bGF5b3V0X2hlaWdodD0ibWF0Y2hfcGFyZW50IgogICAgICAgIGFwcDpsYXlvdXRfY29uc3RyYWludEJvdHRvbV90b0JvdHRvbU9mPSJwYXJlbnQiCiAgICAgICAgYXBwOmxheW91dF9jb25zdHJhaW50TGVmdF90b0xlZnRPZj0icGFyZW50IgogICAgICAgIGFwcDpsYXlvdXRfY29uc3RyYWludFJpZ2h0X3RvUmlnaHRPZj0icGFyZW50IgogICAgICAgIGFwcDpsYXlvdXRfY29uc3RyYWludFRvcF90b1RvcE9mPSJwYXJlbnQiIC8+Cgo8L2FuZHJvaWR4LmNvbnN0cmFpbnRsYXlvdXQud2lkZ2V0LkNvbnN0cmFpbnRMYXlvdXQ+[/fusion_code][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

Add the RecyclerView in an activity layout activity_main.xml layout file and add the following code.

Assign the id to the RecyclerView as “android:id=”@+id/recycler_view_items“.

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPGFuZHJvaWR4LmNvbnN0cmFpbnRsYXlvdXQud2lkZ2V0LkNvbnN0cmFpbnRMYXlvdXQgeG1sbnM6YW5kcm9pZD0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vYXBrL3Jlcy9hbmRyb2lkIgogICAgeG1sbnM6YXBwPSJodHRwOi8vc2NoZW1hcy5hbmRyb2lkLmNvbS9hcGsvcmVzLWF1dG8iCiAgICB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiCiAgICBhbmRyb2lkOmxheW91dF93aWR0aD0ibWF0Y2hfcGFyZW50IgogICAgYW5kcm9pZDpsYXlvdXRfaGVpZ2h0PSJtYXRjaF9wYXJlbnQiCiAgICB0b29sczpjb250ZXh0PSIuTWFpbkFjdGl2aXR5Ij4KCiAgICA8YW5kcm9pZHgucmVjeWNsZXJ2aWV3LndpZGdldC5SZWN5Y2xlclZpZXcKICAgICAgICBhbmRyb2lkOmlkPSJAK2lkL3JlY3ljbGVyX3ZpZXdfaXRlbXMiCiAgICAgICAgYW5kcm9pZDpsYXlvdXRfd2lkdGg9Im1hdGNoX3BhcmVudCIKICAgICAgICBhbmRyb2lkOmxheW91dF9oZWlnaHQ9Im1hdGNoX3BhcmVudCIKICAgICAgICBhcHA6bGF5b3V0X2NvbnN0cmFpbnRCb3R0b21fdG9Cb3R0b21PZj0icGFyZW50IgogICAgICAgIGFwcDpsYXlvdXRfY29uc3RyYWludExlZnRfdG9MZWZ0T2Y9InBhcmVudCIKICAgICAgICBhcHA6bGF5b3V0X2NvbnN0cmFpbnRSaWdodF90b1JpZ2h0T2Y9InBhcmVudCIKICAgICAgICBhcHA6bGF5b3V0X2NvbnN0cmFpbnRUb3BfdG9Ub3BPZj0icGFyZW50IiAvPgoKPC9hbmRyb2lkeC5jb25zdHJhaW50bGF5b3V0LndpZGdldC5Db25zdHJhaW50TGF5b3V0Pg==[/fusion_syntax_highlighter][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

The form you have selected does not exist.

Create a Custom Layout file

[/fusion_title][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]Add the custom layout file for RecyclerView as item_custom_row.xml in the resource layout.

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPExpbmVhckxheW91dCB4bWxuczphbmRyb2lkPSJodHRwOi8vc2NoZW1hcy5hbmRyb2lkLmNvbS9hcGsvcmVzL2FuZHJvaWQiCiAgICB4bWxuczphcHA9Imh0dHA6Ly9zY2hlbWFzLmFuZHJvaWQuY29tL2Fway9yZXMtYXV0byIKICAgIHhtbG5zOnRvb2xzPSJodHRwOi8vc2NoZW1hcy5hbmRyb2lkLmNvbS90b29scyIKICAgIGFuZHJvaWQ6bGF5b3V0X3dpZHRoPSJtYXRjaF9wYXJlbnQiCiAgICBhbmRyb2lkOmxheW91dF9oZWlnaHQ9IndyYXBfY29udGVudCI+CgoKICAgIDxhbmRyb2lkeC5jYXJkdmlldy53aWRnZXQuQ2FyZFZpZXcKICAgICAgICBhbmRyb2lkOmlkPSJAK2lkL2NhcmRfdmlld19pdGVtIgogICAgICAgIGFuZHJvaWQ6bGF5b3V0X3dpZHRoPSJtYXRjaF9wYXJlbnQiCiAgICAgICAgYW5kcm9pZDpsYXlvdXRfaGVpZ2h0PSJ3cmFwX2NvbnRlbnQiCiAgICAgICAgYW5kcm9pZDpsYXlvdXRfbWFyZ2luPSI1ZHAiCiAgICAgICAgYW5kcm9pZDpwYWRkaW5nPSIxMGRwIgogICAgICAgIGFwcDpjYXJkQ29ybmVyUmFkaXVzPSI1ZHAiCiAgICAgICAgYXBwOmNhcmRFbGV2YXRpb249IjNkcCI+CgogICAgICAgIDxMaW5lYXJMYXlvdXQKICAgICAgICAgICAgYW5kcm9pZDpsYXlvdXRfd2lkdGg9Im1hdGNoX3BhcmVudCIKICAgICAgICAgICAgYW5kcm9pZDpsYXlvdXRfaGVpZ2h0PSJ3cmFwX2NvbnRlbnQiCiAgICAgICAgICAgIGFuZHJvaWQ6Z3Jhdml0eT0iY2VudGVyIgogICAgICAgICAgICBhbmRyb2lkOm9yaWVudGF0aW9uPSJob3Jpem9udGFsIgogICAgICAgICAgICB0b29sczppZ25vcmU9IlVzZUNvbXBvdW5kRHJhd2FibGVzIj4KCiAgICAgICAgICAgIDxJbWFnZVZpZXcKICAgICAgICAgICAgICAgIGFuZHJvaWQ6bGF5b3V0X3dpZHRoPSI1MGRwIgogICAgICAgICAgICAgICAgYW5kcm9pZDpsYXlvdXRfaGVpZ2h0PSI1MGRwIgogICAgICAgICAgICAgICAgYW5kcm9pZDpjb250ZW50RGVzY3JpcHRpb249IkBzdHJpbmcvYXBwX25hbWUiCiAgICAgICAgICAgICAgICBhbmRyb2lkOnNyYz0iQG1pcG1hcC9pY19sYXVuY2hlciIgLz4KCiAgICAgICAgICAgIDxUZXh0VmlldwogICAgICAgICAgICAgICAgYW5kcm9pZDppZD0iQCtpZC90dl9pdGVtX25hbWUiCiAgICAgICAgICAgICAgICBhbmRyb2lkOmxheW91dF93aWR0aD0ibWF0Y2hfcGFyZW50IgogICAgICAgICAgICAgICAgYW5kcm9pZDpsYXlvdXRfaGVpZ2h0PSJ3cmFwX2NvbnRlbnQiCiAgICAgICAgICAgICAgICBhbmRyb2lkOmxheW91dF9tYXJnaW49IjEwZHAiCiAgICAgICAgICAgICAgICBhbmRyb2lkOnRleHRDb2xvcj0iQGFuZHJvaWQ6Y29sb3IvYmxhY2siCiAgICAgICAgICAgICAgICBhbmRyb2lkOnRleHRTaXplPSIxOHNwIgogICAgICAgICAgICAgICAgYW5kcm9pZDp0ZXh0U3R5bGU9ImJvbGQiCiAgICAgICAgICAgICAgICB0b29sczp0ZXh0PSJJdGVtIiAvPgogICAgICAgIDwvTGluZWFyTGF5b3V0PgogICAgPC9hbmRyb2lkeC5jYXJkdmlldy53aWRnZXQuQ2FyZFZpZXc+CjwvTGluZWFyTGF5b3V0Pg==[/fusion_syntax_highlighter][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Setup the data resource

[/fusion_title][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

It is basically the list which we will be displaying in the RecyclerView. Here, we are preparing it manually but usually it is from the source like server or database.

Add the below function in the MainActivity.kt.

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]cHJpdmF0ZSBmdW4gZ2V0SXRlbXNMaXN0KCk6IEFycmF5TGlzdDxTdHJpbmc+IHsKICAgICAgICB2YWwgbGlzdCA9IEFycmF5TGlzdDxTdHJpbmc+KCkKCiAgICAgICAgZm9yKGkgaW4gMS4uMTUpewogICAgICAgICAgICBsaXN0LmFkZCgiSXRlbSAkaSIpCiAgICAgICAgfQogICAgICAgIAogICAgICAgIHJldHVybiBsaXN0CiAgICB9[/fusion_syntax_highlighter][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]We have created a list of 15 elements which will be displayed using RecyclerView.

[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Create an Item Adapter Class

[/fusion_title][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

Create an Item Adapter class named ItemAdapter.kt.

Create the view holder for view items, connect the data source of the RecyclerView and handle the view logic by creating a RecyclerView Adapter.

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]cGFja2FnZSBjb20ucmVjeWNsZXJ2aWV3YXBwCgppbXBvcnQgYW5kcm9pZC5jb250ZW50LkNvbnRleHQKaW1wb3J0IGFuZHJvaWQudmlldy5MYXlvdXRJbmZsYXRlcgppbXBvcnQgYW5kcm9pZC52aWV3LlZpZXcKaW1wb3J0IGFuZHJvaWQudmlldy5WaWV3R3JvdXAKaW1wb3J0IGFuZHJvaWR4LmNvcmUuY29udGVudC5Db250ZXh0Q29tcGF0CmltcG9ydCBhbmRyb2lkeC5yZWN5Y2xlcnZpZXcud2lkZ2V0LlJlY3ljbGVyVmlldwppbXBvcnQga290bGlueC5hbmRyb2lkLnN5bnRoZXRpYy5tYWluLml0ZW1fY3VzdG9tX3Jvdy52aWV3LioKCmNsYXNzIEl0ZW1BZGFwdGVyKHZhbCBjb250ZXh0OiBDb250ZXh0LCB2YWwgaXRlbXM6IEFycmF5TGlzdDxTdHJpbmc+KSA6CiAgICBSZWN5Y2xlclZpZXcuQWRhcHRlcjxJdGVtQWRhcHRlci5WaWV3SG9sZGVyPigpIHsKCiAgICAvKioKICAgICAqIEluZmxhdGVzIHRoZSBpdGVtIHZpZXdzIHdoaWNoIGlzIGRlc2lnbmVkIGluIHhtbCBsYXlvdXQgZmlsZQogICAgICoKICAgICAqIGNyZWF0ZSBhIG5ldwogICAgICoge0BsaW5rIFZpZXdIb2xkZXJ9IGFuZCBpbml0aWFsaXplcyBzb21lIHByaXZhdGUgZmllbGRzIHRvIGJlIHVzZWQgYnkgUmVjeWNsZXJWaWV3LgogICAgICovCiAgICBvdmVycmlkZSBmdW4gb25DcmVhdGVWaWV3SG9sZGVyKHBhcmVudDogVmlld0dyb3VwLCB2aWV3VHlwZTogSW50KTogVmlld0hvbGRlciB7CiAgICAgICAgcmV0dXJuIFZpZXdIb2xkZXIoCiAgICAgICAgICAgIExheW91dEluZmxhdGVyLmZyb20oY29udGV4dCkuaW5mbGF0ZSgKICAgICAgICAgICAgICAgIFIubGF5b3V0Lml0ZW1fY3VzdG9tX3JvdywKICAgICAgICAgICAgICAgIHBhcmVudCwKICAgICAgICAgICAgICAgIGZhbHNlCiAgICAgICAgICAgICkKICAgICAgICApCiAgICB9CgogICAgLyoqCiAgICAgKiBCaW5kcyBlYWNoIGl0ZW0gaW4gdGhlIEFycmF5TGlzdCB0byBhIHZpZXcKICAgICAqCiAgICAgKiBDYWxsZWQgd2hlbiBSZWN5Y2xlclZpZXcgbmVlZHMgYSBuZXcge0BsaW5rIFZpZXdIb2xkZXJ9IG9mIHRoZSBnaXZlbiB0eXBlIHRvIHJlcHJlc2VudAogICAgICogYW4gaXRlbS4KICAgICAqCiAgICAgKiBUaGlzIG5ldyBWaWV3SG9sZGVyIHNob3VsZCBiZSBjb25zdHJ1Y3RlZCB3aXRoIGEgbmV3IFZpZXcgdGhhdCBjYW4gcmVwcmVzZW50IHRoZSBpdGVtcwogICAgICogb2YgdGhlIGdpdmVuIHR5cGUuIFlvdSBjYW4gZWl0aGVyIGNyZWF0ZSBhIG5ldyBWaWV3IG1hbnVhbGx5IG9yIGluZmxhdGUgaXQgZnJvbSBhbiBYTUwKICAgICAqIGxheW91dCBmaWxlLgogICAgICovCiAgICBvdmVycmlkZSBmdW4gb25CaW5kVmlld0hvbGRlcihob2xkZXI6IFZpZXdIb2xkZXIsIHBvc2l0aW9uOiBJbnQpIHsKCiAgICAgICAgdmFsIGl0ZW0gPSBpdGVtcy5nZXQocG9zaXRpb24pCgogICAgICAgIGhvbGRlci50dkl0ZW0udGV4dCA9IGl0ZW0KCiAgICAgICAgLy8gVXBkYXRpbmcgdGhlIGJhY2tncm91bmQgY29sb3IgYWNjb3JkaW5nIHRvIHRoZSBvZGQvZXZlbiBwb3NpdGlvbnMgaW4gbGlzdC4KICAgICAgICBpZiAocG9zaXRpb24gJSAyID09IDApIHsKICAgICAgICAgICAgaG9sZGVyLmNhcmRWaWV3SXRlbS5zZXRCYWNrZ3JvdW5kQ29sb3IoCiAgICAgICAgICAgICAgICBDb250ZXh0Q29tcGF0LmdldENvbG9yKAogICAgICAgICAgICAgICAgICAgIGNvbnRleHQsCiAgICAgICAgICAgICAgICAgICAgUi5jb2xvci5jb2xvckxpZ2h0R3JheQogICAgICAgICAgICAgICAgKQogICAgICAgICAgICApCiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaG9sZGVyLmNhcmRWaWV3SXRlbS5zZXRCYWNrZ3JvdW5kQ29sb3IoCiAgICAgICAgICAgICAgICBDb250ZXh0Q29tcGF0LmdldENvbG9yKAogICAgICAgICAgICAgICAgICAgIGNvbnRleHQsCiAgICAgICAgICAgICAgICAgICAgUi5jb2xvci5jb2xvcldoaXRlCiAgICAgICAgICAgICAgICApCiAgICAgICAgICAgICkKICAgICAgICB9CiAgICB9CgogICAgLyoqCiAgICAgKiBHZXRzIHRoZSBudW1iZXIgb2YgaXRlbXMgaW4gdGhlIGxpc3QKICAgICAqLwogICAgb3ZlcnJpZGUgZnVuIGdldEl0ZW1Db3VudCgpOiBJbnQgewogICAgICAgIHJldHVybiBpdGVtcy5zaXplCiAgICB9CgogICAgLyoqCiAgICAgKiBBIFZpZXdIb2xkZXIgZGVzY3JpYmVzIGFuIGl0ZW0gdmlldyBhbmQgbWV0YWRhdGEgYWJvdXQgaXRzIHBsYWNlIHdpdGhpbiB0aGUgUmVjeWNsZXJWaWV3LgogICAgICovCiAgICBjbGFzcyBWaWV3SG9sZGVyKHZpZXc6IFZpZXcpIDogUmVjeWNsZXJWaWV3LlZpZXdIb2xkZXIodmlldykgewogICAgICAgIC8vIEhvbGRzIHRoZSBUZXh0VmlldyB0aGF0IHdpbGwgYWRkIGVhY2ggaXRlbSB0bwogICAgICAgIHZhbCB0dkl0ZW0gPSB2aWV3LnR2X2l0ZW1fbmFtZQogICAgICAgIHZhbCBjYXJkVmlld0l0ZW0gPSB2aWV3LmNhcmRfdmlld19pdGVtCiAgICB9Cn0=[/fusion_syntax_highlighter][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

We have used the custom layout file to bind the views to the RecyclerView. In the onCreateViewHolder function we have inflated it.
In the onBindViewHolder function we have set the text to the TextView from the data list. Also, we have add the different background colors to the CardView based on the odd and even positions.
Add the below colors in the colors.xml file.

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]PGNvbG9yIG5hbWU9ImNvbG9yV2hpdGUiPiNGRkZGRkY8L2NvbG9yPgo8Y29sb3IgbmFtZT0iY29sb3JMaWdodEdyYXkiPiNFQkVCRUI8L2NvbG9yPg==[/fusion_syntax_highlighter][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

Now, as we have everything that is required.
Attach the adapter to the RecyclerView.
After, attaching the RecyclerView to the adapter class the MainActivity.kt will look like this:

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]cGFja2FnZSBjb20ucmVjeWNsZXJ2aWV3YXBwCgppbXBvcnQgYW5kcm9pZC5vcy5CdW5kbGUKaW1wb3J0IGFuZHJvaWR4LmFwcGNvbXBhdC5hcHAuQXBwQ29tcGF0QWN0aXZpdHkKaW1wb3J0IGFuZHJvaWR4LnJlY3ljbGVydmlldy53aWRnZXQuTGluZWFyTGF5b3V0TWFuYWdlcgppbXBvcnQga290bGlueC5hbmRyb2lkLnN5bnRoZXRpYy5tYWluLmFjdGl2aXR5X21haW4uKgoKY2xhc3MgTWFpbkFjdGl2aXR5IDogQXBwQ29tcGF0QWN0aXZpdHkoKSB7CiAgICBvdmVycmlkZSBmdW4gb25DcmVhdGUoc2F2ZWRJbnN0YW5jZVN0YXRlOiBCdW5kbGU/KSB7CiAgICAgICAgc3VwZXIub25DcmVhdGUoc2F2ZWRJbnN0YW5jZVN0YXRlKQogICAgICAgIHNldENvbnRlbnRWaWV3KFIubGF5b3V0LmFjdGl2aXR5X21haW4pCgogICAgICAgLy8gU2V0IHRoZSBMYXlvdXRNYW5hZ2VyIHRoYXQgdGhpcyBSZWN5Y2xlclZpZXcgd2lsbCB1c2UuCiAgICAgICAgcmVjeWNsZXJfdmlld19pdGVtcy5sYXlvdXRNYW5hZ2VyID0gTGluZWFyTGF5b3V0TWFuYWdlcih0aGlzKQogICAgICAgIAogICAgICAgIC8vIEFkYXB0ZXIgY2xhc3MgaXMgaW5pdGlhbGl6ZWQgYW5kIGxpc3QgaXMgcGFzc2VkIGluIHRoZSBwYXJhbS4KICAgICAgICB2YWwgaXRlbUFkYXB0ZXIgPSBJdGVtQWRhcHRlcih0aGlzLCBnZXRJdGVtc0xpc3QoKSkKICAgICAgICAKICAgICAgICAvLyBhZGFwdGVyIGluc3RhbmNlIGlzIHNldCB0byB0aGUgcmVjeWNsZXJ2aWV3IHRvIGluZmxhdGUgdGhlIGl0ZW1zLgogICAgICAgIHJlY3ljbGVyX3ZpZXdfaXRlbXMuYWRhcHRlciA9IGl0ZW1BZGFwdGVyCiAgICB9CgogICAgLyoqCiAgICAgKiBGdW5jdGlvbiBpcyB1c2VkIHRvIGdldCB0aGUgSXRlbXMgTGlzdCB3aGljaCBpcyBhZGRlZCBpbiB0aGUgbGlzdC4KICAgICAqLwogICAgcHJpdmF0ZSBmdW4gZ2V0SXRlbXNMaXN0KCk6IEFycmF5TGlzdDxTdHJpbmc+IHsKICAgICAgICB2YWwgbGlzdCA9IEFycmF5TGlzdDxTdHJpbmc+KCkKCiAgICAgICAgZm9yIChpIGluIDEuLjE1KSB7CiAgICAgICAgICAgIGxpc3QuYWRkKCJJdGVtICRpIikKICAgICAgICB9CgogICAgICAgIHJldHVybiBsaXN0CiAgICB9Cn0=[/fusion_syntax_highlighter][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

 

The LayoutManager used here is LinearLayoutManager for the RecyclerView.

Adapter class is initialized and data list is passed to it.

Finally, the adapter class is attached to the RecyclerView.

Run the app and check the output.

[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Output using the LinearLayoutManager

[/fusion_title][fusion_imageframe image_id=”4171|fusion-400″ max_width=”” style_type=”none” blur=”” stylecolor=”” hover_type=”none” bordersize=”” bordercolor=”” borderradius=”” align=”center” lightbox=”no” gallery_id=”” lightbox_image=”” lightbox_image_id=”” alt=”” link=”” linktarget=”_self” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″]https://tutorials.eu/wp-content/uploads/2020/07/Output-1-400×889.png[/fusion_imageframe][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” rotation_text=”” highlight_text=”” after_text=”” content_align=”left” size=”1″ font_size=”” animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” /][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

RecyclerView using LinearLayoutManager with Horizontal Scroll

[/fusion_title][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]As we can see in the above output the items are displayed in the vertical format and can be scrolled vertically.

 

Now add some more parameters using the LinearLayoutManager we can also display the items in the horizontal format.

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]cmVjeWNsZXJfdmlld19pdGVtcy5sYXlvdXRNYW5hZ2VyID0gTGluZWFyTGF5b3V0TWFuYWdlcih0aGlzLCBMaW5lYXJMYXlvdXRNYW5hZ2VyLkhPUklaT05UQUwsIGZhbHNlKQ==[/fusion_syntax_highlighter][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

 

By default the scrolling direction it vertical.

For the horizontal we need to pass the direction as LinearLayoutManager.HORIZONTAL and reverse layout as true or false as per requirement.

The form you have selected does not exist.

 

Now you will be able to scroll the items in the horizontal format.

[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Output using the LinearLayoutManager in Horizontal Scroll

[/fusion_title][fusion_imageframe image_id=”4172|fusion-400″ max_width=”” style_type=”” blur=”” stylecolor=”” hover_type=”none” bordersize=”” bordercolor=”” borderradius=”” align=”center” lightbox=”no” gallery_id=”” lightbox_image=”” lightbox_image_id=”” alt=”” link=”” linktarget=”_self” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″]https://tutorials.eu/wp-content/uploads/2020/07/Output-2-400×889.png[/fusion_imageframe][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

RecyclerView using GridLayoutManager

[/fusion_title][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

Now display the items views using the GridLayoutManager instead of LinearLayoutManager in the RecyclerView.

Replace the layout manager in the MainActivity.kt onCreate function.

Replace the below line of code.

[/fusion_text][fusion_syntax_highlighter theme=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]cmVjeWNsZXJfdmlld19pdGVtcy5sYXlvdXRNYW5hZ2VyID0gTGluZWFyTGF5b3V0TWFuYWdlcih0aGlzKQ==[/fusion_syntax_highlighter][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

 

Replace it with GridLayoutManager.

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]IHJlY3ljbGVyX3ZpZXdfaXRlbXMubGF5b3V0TWFuYWdlciA9IEdyaWRMYXlvdXRNYW5hZ2VyKHRoaXMsIDIp[/fusion_syntax_highlighter][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

 

In the GridLayoutManager you need to pass the span count as in our case it is 2 which will impact the grid column count.

[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Output using the GridLayoutManager

[/fusion_title][fusion_imageframe image_id=”4173|fusion-400″ max_width=”” style_type=”” blur=”” stylecolor=”” hover_type=”none” bordersize=”” bordercolor=”” borderradius=”” align=”center” lightbox=”no” gallery_id=”” lightbox_image=”” lightbox_image_id=”” alt=”” link=”” linktarget=”_self” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″]https://tutorials.eu/wp-content/uploads/2020/07/Output-3-400×889.png[/fusion_imageframe][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container][fusion_builder_container hundred_percent=”no” hundred_percent_height=”no” hundred_percent_height_scroll=”no” hundred_percent_height_center_content=”yes” equal_height_columns=”no” menu_anchor=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” status=”published” publish_date=”” class=”” id=”” link_color=”” link_hover_color=”” border_size=”” border_color=”” border_style=”solid” margin_top=”” margin_bottom=”” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” gradient_start_color=”” gradient_end_color=”” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_color=”” background_image=”” background_position=”center center” background_repeat=”no-repeat” fade=”no” background_parallax=”none” enable_mobile=”no” parallax_speed=”0.3″ background_blend_mode=”none” video_mp4=”” video_webm=”” video_ogv=”” video_url=”” video_aspect_ratio=”16:9″ video_loop=”yes” video_mute=”yes” video_preview_image=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″][fusion_builder_row][fusion_builder_column type=”1_1″ layout=”1_1″ spacing=”” center_content=”no” link=”” target=”_self” min_height=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” hover_type=”none” border_size=”0″ border_color=”” border_style=”solid” border_position=”all” box_shadow=”no” box_shadow_blur=”0″ box_shadow_spread=”0″ box_shadow_color=”” box_shadow_style=”” background_type=”single” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_color=”” background_image=”” background_image_id=”” background_position=”left top” background_repeat=”no-repeat” background_blend_mode=”none” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” filter_type=”regular” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″ first=”true” last=”true”][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”2″ font_size=”30″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]RecyclerView with Multiple View Types[/fusion_title][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

You might have noticed and seen that while using a RecyclerView, we define a view and the list items are displayed according to that view only. But what if you want to add different view types in the RecyclerView, you can add Multiple Views in the same RecyclerView.

We can add multiple views in a single RecyclerView. For example, the home page on Facebook and Instagram is an example of Multiple Views. You can add an image, video, text or a combination of all of them in the same RecyclerView.

We’ll use the same project that we have done above and make the changes for another view type.

We’ll use the LinearLayoutManager as the layout manager in the RecyclerView.

For LinearLayoutManager replace the layout manager line in MainActivity.kt as below.

recycler_view_items.layoutManager = LinearLayoutManager(this)

[/fusion_text][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Create a Another Custom Layout file

[/fusion_title][fusion_text columns=”1″ column_min_width=”” column_spacing=”” rule_style=”default” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

Add the custom layout file for RecyclerView as item_another_custom_row.xml in the resource layout.

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPExpbmVhckxheW91dCB4bWxuczphbmRyb2lkPSJodHRwOi8vc2NoZW1hcy5hbmRyb2lkLmNvbS9hcGsvcmVzL2FuZHJvaWQiCiAgICB4bWxuczphcHA9Imh0dHA6Ly9zY2hlbWFzLmFuZHJvaWQuY29tL2Fway9yZXMtYXV0byIKICAgIHhtbG5zOnRvb2xzPSJodHRwOi8vc2NoZW1hcy5hbmRyb2lkLmNvbS90b29scyIKICAgIGFuZHJvaWQ6bGF5b3V0X3dpZHRoPSJtYXRjaF9wYXJlbnQiCiAgICBhbmRyb2lkOmxheW91dF9oZWlnaHQ9IndyYXBfY29udGVudCI+CgogICAgPGFuZHJvaWR4LmNhcmR2aWV3LndpZGdldC5DYXJkVmlldwogICAgICAgIGFuZHJvaWQ6aWQ9IkAraWQvY2FyZF92aWV3X2Fub3RoZXJfaXRlbSIKICAgICAgICBhbmRyb2lkOmxheW91dF93aWR0aD0ibWF0Y2hfcGFyZW50IgogICAgICAgIGFuZHJvaWQ6bGF5b3V0X2hlaWdodD0id3JhcF9jb250ZW50IgogICAgICAgIGFuZHJvaWQ6bGF5b3V0X21hcmdpbj0iNWRwIgogICAgICAgIGFuZHJvaWQ6cGFkZGluZz0iMTBkcCIKICAgICAgICBhcHA6Y2FyZENvcm5lclJhZGl1cz0iNWRwIgogICAgICAgIGFwcDpjYXJkRWxldmF0aW9uPSIzZHAiPgoKICAgICAgICA8TGluZWFyTGF5b3V0CiAgICAgICAgICAgIGFuZHJvaWQ6bGF5b3V0X3dpZHRoPSJtYXRjaF9wYXJlbnQiCiAgICAgICAgICAgIGFuZHJvaWQ6bGF5b3V0X2hlaWdodD0id3JhcF9jb250ZW50IgogICAgICAgICAgICBhbmRyb2lkOmdyYXZpdHk9ImNlbnRlciIKICAgICAgICAgICAgYW5kcm9pZDpvcmllbnRhdGlvbj0idmVydGljYWwiCiAgICAgICAgICAgIHRvb2xzOmlnbm9yZT0iVXNlQ29tcG91bmREcmF3YWJsZXMiPgoKICAgICAgICAgICAgPEltYWdlVmlldwogICAgICAgICAgICAgICAgYW5kcm9pZDpsYXlvdXRfd2lkdGg9IjUwZHAiCiAgICAgICAgICAgICAgICBhbmRyb2lkOmxheW91dF9oZWlnaHQ9IjUwZHAiCiAgICAgICAgICAgICAgICBhbmRyb2lkOmxheW91dF9tYXJnaW5Ub3A9IjVkcCIKICAgICAgICAgICAgICAgIGFuZHJvaWQ6Y29udGVudERlc2NyaXB0aW9uPSJAc3RyaW5nL2FwcF9uYW1lIgogICAgICAgICAgICAgICAgYW5kcm9pZDpzcmM9IkBtaXBtYXAvaWNfbGF1bmNoZXIiIC8+CgogICAgICAgICAgICA8VGV4dFZpZXcKICAgICAgICAgICAgICAgIGFuZHJvaWQ6aWQ9IkAraWQvdHZfYW5vdGhlcl9pdGVtX25hbWUiCiAgICAgICAgICAgICAgICBhbmRyb2lkOmxheW91dF93aWR0aD0id3JhcF9jb250ZW50IgogICAgICAgICAgICAgICAgYW5kcm9pZDpsYXlvdXRfaGVpZ2h0PSJ3cmFwX2NvbnRlbnQiCiAgICAgICAgICAgICAgICBhbmRyb2lkOmxheW91dF9tYXJnaW49IjEwZHAiCiAgICAgICAgICAgICAgICBhbmRyb2lkOnRleHRDb2xvcj0iQGFuZHJvaWQ6Y29sb3IvYmxhY2siCiAgICAgICAgICAgICAgICBhbmRyb2lkOnRleHRTaXplPSIxOHNwIgogICAgICAgICAgICAgICAgYW5kcm9pZDp0ZXh0U3R5bGU9ImJvbGQiCiAgICAgICAgICAgICAgICB0b29sczp0ZXh0PSJJdGVtIiAvPgoKICAgICAgICA8L0xpbmVhckxheW91dD4KICAgIDwvYW5kcm9pZHguY2FyZHZpZXcud2lkZ2V0LkNhcmRWaWV3Pgo8L0xpbmVhckxheW91dD4=[/fusion_syntax_highlighter][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Create a Data Model Class

[/fusion_title][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

The data model class is used to create a custom data type list.

Create the data model class name as DataModel.kt.

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]cGFja2FnZSBjb20ucmVjeWNsZXJ2aWV3YXBwCgpkYXRhIGNsYXNzIERhdGFNb2RlbCh2YWwgaXRlbU5hbWU6IFN0cmluZywgdmFsIHZpZXdUeXBlOiBJbnQp[/fusion_syntax_highlighter][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Update an Item Adapter Class

[/fusion_title][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

In the Item adapter class we need to make the following changes as below:

  • Update the list data type from string to data model class.
  • Update the implementation parameter as RecyclerView.ViewHolder instead of ItemAdapter.ViewHolder.
  • Declare the constants for View Types in companion object.
  • Override the function as getItemViewType.
  • Add another viewholder inner class.
  • Update the onCreateViewHolder and onBindViewHolder functions as per view types.
  • The ItemAdapter.kt will look like below.

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]cGFja2FnZSBjb20ucmVjeWNsZXJ2aWV3YXBwCgppbXBvcnQgYW5kcm9pZC5jb250ZW50LkNvbnRleHQKaW1wb3J0IGFuZHJvaWQudmlldy5MYXlvdXRJbmZsYXRlcgppbXBvcnQgYW5kcm9pZC52aWV3LlZpZXcKaW1wb3J0IGFuZHJvaWQudmlldy5WaWV3R3JvdXAKaW1wb3J0IGFuZHJvaWR4LmNvcmUuY29udGVudC5Db250ZXh0Q29tcGF0CmltcG9ydCBhbmRyb2lkeC5yZWN5Y2xlcnZpZXcud2lkZ2V0LlJlY3ljbGVyVmlldwppbXBvcnQga290bGlueC5hbmRyb2lkLnN5bnRoZXRpYy5tYWluLml0ZW1fYW5vdGhlcl9jdXN0b21fcm93LnZpZXcuKgppbXBvcnQga290bGlueC5hbmRyb2lkLnN5bnRoZXRpYy5tYWluLml0ZW1fY3VzdG9tX3Jvdy52aWV3LioKCmNsYXNzIEl0ZW1BZGFwdGVyKHZhbCBjb250ZXh0OiBDb250ZXh0LCB2YWwgaXRlbXM6IEFycmF5TGlzdDxEYXRhTW9kZWw+KSA6CiAgICBSZWN5Y2xlclZpZXcuQWRhcHRlcjxSZWN5Y2xlclZpZXcuVmlld0hvbGRlcj4oKSB7CgogICAgLyoqCiAgICAgKiBBIGNvbXBhbmlvbiBvYmplY3Qgd2hlcmUgd2UgY2FuIGRlY2xhcmUgdGhlIGNvbnN0YW50IHZhbHVlcy4KICAgICAqLwogICAgY29tcGFuaW9uIG9iamVjdCB7CiAgICAgICAgY29uc3QgdmFsIFZJRVdfVFlQRV9PTkUgPSAxCiAgICAgICAgY29uc3QgdmFsIFZJRVdfVFlQRV9UV08gPSAyCiAgICB9CgogICAgLyoqCiAgICAgKiBJbmZsYXRlcyB0aGUgaXRlbSB2aWV3cyB3aGljaCBpcyBkZXNpZ25lZCBpbiB4bWwgbGF5b3V0IGZpbGUKICAgICAqCiAgICAgKiBjcmVhdGUgYSBuZXcKICAgICAqIHtAbGluayBWaWV3SG9sZGVyfSBhbmQgaW5pdGlhbGl6ZXMgc29tZSBwcml2YXRlIGZpZWxkcyB0byBiZSB1c2VkIGJ5IFJlY3ljbGVyVmlldy4KICAgICAqLwogICAgb3ZlcnJpZGUgZnVuIG9uQ3JlYXRlVmlld0hvbGRlcihwYXJlbnQ6IFZpZXdHcm91cCwgdmlld1R5cGU6IEludCk6IFJlY3ljbGVyVmlldy5WaWV3SG9sZGVyIHsKCiAgICAgICAgaWYgKHZpZXdUeXBlID09IFZJRVdfVFlQRV9PTkUpIHsKICAgICAgICAgICAgcmV0dXJuIFZpZXdIb2xkZXIoCiAgICAgICAgICAgICAgICBMYXlvdXRJbmZsYXRlci5mcm9tKGNvbnRleHQpLmluZmxhdGUoCiAgICAgICAgICAgICAgICAgICAgUi5sYXlvdXQuaXRlbV9jdXN0b21fcm93LAogICAgICAgICAgICAgICAgICAgIHBhcmVudCwKICAgICAgICAgICAgICAgICAgICBmYWxzZQogICAgICAgICAgICAgICAgKQogICAgICAgICAgICApCiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIEFub3RoZXJWaWV3SG9sZGVyKAogICAgICAgICAgICAgICAgTGF5b3V0SW5mbGF0ZXIuZnJvbShjb250ZXh0KS5pbmZsYXRlKAogICAgICAgICAgICAgICAgICAgIFIubGF5b3V0Lml0ZW1fYW5vdGhlcl9jdXN0b21fcm93LAogICAgICAgICAgICAgICAgICAgIHBhcmVudCwKICAgICAgICAgICAgICAgICAgICBmYWxzZQogICAgICAgICAgICAgICAgKQogICAgICAgICAgICApCiAgICAgICAgfQogICAgfQoKICAgIC8qKgogICAgICogQmluZHMgZWFjaCBpdGVtIGluIHRoZSBBcnJheUxpc3QgdG8gYSB2aWV3CiAgICAgKgogICAgICogQ2FsbGVkIHdoZW4gUmVjeWNsZXJWaWV3IG5lZWRzIGEgbmV3IHtAbGluayBWaWV3SG9sZGVyfSBvZiB0aGUgZ2l2ZW4gdHlwZSB0byByZXByZXNlbnQKICAgICAqIGFuIGl0ZW0uCiAgICAgKgogICAgICogVGhpcyBuZXcgVmlld0hvbGRlciBzaG91bGQgYmUgY29uc3RydWN0ZWQgd2l0aCBhIG5ldyBWaWV3IHRoYXQgY2FuIHJlcHJlc2VudCB0aGUgaXRlbXMKICAgICAqIG9mIHRoZSBnaXZlbiB0eXBlLiBZb3UgY2FuIGVpdGhlciBjcmVhdGUgYSBuZXcgVmlldyBtYW51YWxseSBvciBpbmZsYXRlIGl0IGZyb20gYW4gWE1MCiAgICAgKiBsYXlvdXQgZmlsZS4KICAgICAqLwogICAgb3ZlcnJpZGUgZnVuIG9uQmluZFZpZXdIb2xkZXIoaG9sZGVyOiBSZWN5Y2xlclZpZXcuVmlld0hvbGRlciwgcG9zaXRpb246IEludCkgewoKICAgICAgICB2YWwgaXRlbSA9IGl0ZW1zLmdldChwb3NpdGlvbikKCiAgICAgICAgaWYgKGhvbGRlciBpcyBWaWV3SG9sZGVyKSB7CiAgICAgICAgICAgIGhvbGRlci50dkl0ZW0udGV4dCA9IGl0ZW0uaXRlbU5hbWUKCiAgICAgICAgICAgIC8vIFVwZGF0aW5nIHRoZSBiYWNrZ3JvdW5kIGNvbG9yIGFjY29yZGluZyB0byB0aGUgb2RkL2V2ZW4gcG9zaXRpb25zIGluIGxpc3QuCiAgICAgICAgICAgIGlmIChwb3NpdGlvbiAlIDIgPT0gMCkgewogICAgICAgICAgICAgICAgaG9sZGVyLmNhcmRWaWV3SXRlbS5zZXRCYWNrZ3JvdW5kQ29sb3IoCiAgICAgICAgICAgICAgICAgICAgQ29udGV4dENvbXBhdC5nZXRDb2xvcigKICAgICAgICAgICAgICAgICAgICAgICAgY29udGV4dCwKICAgICAgICAgICAgICAgICAgICAgICAgUi5jb2xvci5jb2xvckxpZ2h0R3JheQogICAgICAgICAgICAgICAgICAgICkKICAgICAgICAgICAgICAgICkKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGhvbGRlci5jYXJkVmlld0l0ZW0uc2V0QmFja2dyb3VuZENvbG9yKAogICAgICAgICAgICAgICAgICAgIENvbnRleHRDb21wYXQuZ2V0Q29sb3IoCiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRleHQsCiAgICAgICAgICAgICAgICAgICAgICAgIFIuY29sb3IuY29sb3JXaGl0ZQogICAgICAgICAgICAgICAgICAgICkKICAgICAgICAgICAgICAgICkKICAgICAgICAgICAgfQogICAgICAgIH0gZWxzZSBpZiAoaG9sZGVyIGlzIEFub3RoZXJWaWV3SG9sZGVyKSB7CiAgICAgICAgICAgIGhvbGRlci50dkFub3RoZXJJdGVtTmFtZS50ZXh0ID0gaXRlbS5pdGVtTmFtZQoKICAgICAgICAgICAgLy8gVXBkYXRpbmcgdGhlIGJhY2tncm91bmQgY29sb3IgYWNjb3JkaW5nIHRvIHRoZSBvZGQvZXZlbiBwb3NpdGlvbnMgaW4gbGlzdC4KICAgICAgICAgICAgaWYgKHBvc2l0aW9uICUgMiA9PSAwKSB7CiAgICAgICAgICAgICAgICBob2xkZXIuY2FyZFZpZXdBbm90aGVySXRlbS5zZXRCYWNrZ3JvdW5kQ29sb3IoCiAgICAgICAgICAgICAgICAgICAgQ29udGV4dENvbXBhdC5nZXRDb2xvcigKICAgICAgICAgICAgICAgICAgICAgICAgY29udGV4dCwKICAgICAgICAgICAgICAgICAgICAgICAgUi5jb2xvci5jb2xvckxpZ2h0R3JheQogICAgICAgICAgICAgICAgICAgICkKICAgICAgICAgICAgICAgICkKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGhvbGRlci5jYXJkVmlld0Fub3RoZXJJdGVtLnNldEJhY2tncm91bmRDb2xvcigKICAgICAgICAgICAgICAgICAgICBDb250ZXh0Q29tcGF0LmdldENvbG9yKAogICAgICAgICAgICAgICAgICAgICAgICBjb250ZXh0LAogICAgICAgICAgICAgICAgICAgICAgICBSLmNvbG9yLmNvbG9yV2hpdGUKICAgICAgICAgICAgICAgICAgICApCiAgICAgICAgICAgICAgICApCiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgLyoqCiAgICAgKiBHZXRzIHRoZSBudW1iZXIgb2YgaXRlbXMgaW4gdGhlIGxpc3QKICAgICAqLwogICAgb3ZlcnJpZGUgZnVuIGdldEl0ZW1Db3VudCgpOiBJbnQgewogICAgICAgIHJldHVybiBpdGVtcy5zaXplCiAgICB9CgogICAgLyoqCiAgICAgKiBHZXQgdGhlIEl0ZW1WaWV3VHlwZSBmcm9tIHRoZSBsaXN0IGl0ZW1zLgogICAgICovCiAgICBvdmVycmlkZSBmdW4gZ2V0SXRlbVZpZXdUeXBlKHBvc2l0aW9uOiBJbnQpOiBJbnQgewogICAgICAgIHJldHVybiBpdGVtc1twb3NpdGlvbl0udmlld1R5cGUKICAgIH0KCiAgICAvKioKICAgICAqIEEgVmlld0hvbGRlciBkZXNjcmliZXMgYW4gaXRlbSB2aWV3IGFuZCBtZXRhZGF0YSBhYm91dCBpdHMgcGxhY2Ugd2l0aGluIHRoZSBSZWN5Y2xlclZpZXcuCiAgICAgKi8KICAgIGNsYXNzIFZpZXdIb2xkZXIodmlldzogVmlldykgOiBSZWN5Y2xlclZpZXcuVmlld0hvbGRlcih2aWV3KSB7CiAgICAgICAgLy8gSG9sZHMgdGhlIFRleHRWaWV3IHRoYXQgd2lsbCBhZGQgZWFjaCBpdGVtIHRvCiAgICAgICAgdmFsIHR2SXRlbSA9IHZpZXcudHZfaXRlbV9uYW1lCiAgICAgICAgdmFsIGNhcmRWaWV3SXRlbSA9IHZpZXcuY2FyZF92aWV3X2l0ZW0KICAgIH0KCiAgICBjbGFzcyBBbm90aGVyVmlld0hvbGRlcih2aWV3OiBWaWV3KSA6IFJlY3ljbGVyVmlldy5WaWV3SG9sZGVyKHZpZXcpIHsKICAgICAgICAvLyBIb2xkcyB0aGUgVGV4dFZpZXcgdGhhdCB3aWxsIGFkZCBlYWNoIGl0ZW0gdG8KICAgICAgICB2YWwgdHZBbm90aGVySXRlbU5hbWUgPSB2aWV3LnR2X2Fub3RoZXJfaXRlbV9uYW1lCiAgICAgICAgdmFsIGNhcmRWaWV3QW5vdGhlckl0ZW0gPSB2aWV3LmNhcmRfdmlld19hbm90aGVyX2l0ZW0KICAgIH0KfQ==[/fusion_syntax_highlighter][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container][fusion_builder_container hundred_percent=”no” hundred_percent_height=”no” hundred_percent_height_scroll=”no” hundred_percent_height_center_content=”yes” equal_height_columns=”no” menu_anchor=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” status=”published” publish_date=”” class=”” id=”” link_color=”” link_hover_color=”” border_size=”” border_color=”” border_style=”solid” margin_top=”” margin_bottom=”” padding_top=”” padding_right=”” padding_bottom=”” padding_left=”” gradient_start_color=”” gradient_end_color=”” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_color=”” background_image=”” background_position=”center center” background_repeat=”no-repeat” fade=”no” background_parallax=”none” enable_mobile=”no” parallax_speed=”0.3″ background_blend_mode=”none” video_mp4=”” video_webm=”” video_ogv=”” video_url=”” video_aspect_ratio=”16:9″ video_loop=”yes” video_mute=”yes” video_preview_image=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″][fusion_builder_row][fusion_builder_column type=”1_1″ layout=”1_1″ spacing=”” center_content=”no” link=”” target=”_self” min_height=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” hover_type=”none” border_size=”0″ border_color=”” border_style=”solid” border_position=”all” box_shadow=”no” box_shadow_blur=”0″ box_shadow_spread=”0″ box_shadow_color=”” box_shadow_style=”” background_type=”single” gradient_start_position=”0″ gradient_end_position=”100″ gradient_type=”linear” radial_direction=”center center” linear_angle=”180″ background_color=”” background_image=”” background_image_id=”” background_position=”left top” background_repeat=”no-repeat” background_blend_mode=”none” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” filter_type=”regular” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″ first=”true” last=”true”][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Update Data Resource List

[/fusion_title][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

Update the data resource list using data model class as DataModel.kt.

Update the getItemsList function in MainActivity.kt as below.

[/fusion_text][fusion_syntax_highlighter theme=”” language=”” line_numbers=”” line_wrapping=”” copy_to_clipboard=”” copy_to_clipboard_text=”” font_size=”” border_size=”” border_color=”” border_style=”” background_color=”” line_number_background_color=”” line_number_text_color=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]cHJpdmF0ZSBmdW4gZ2V0SXRlbXNMaXN0KCk6IEFycmF5TGlzdDxEYXRhTW9kZWw+IHsKICAgICAgICB2YWwgbGlzdCA9IEFycmF5TGlzdDxEYXRhTW9kZWw+KCkKCiAgICAgICAgbGlzdC5hZGQoRGF0YU1vZGVsKCJJdGVtIDEgVmlld1R5cGUgMSIsIEl0ZW1BZGFwdGVyLlZJRVdfVFlQRV9PTkUpKQogICAgICAgIGxpc3QuYWRkKERhdGFNb2RlbCgiSXRlbSAyIFZpZXdUeXBlIDIiLCBJdGVtQWRhcHRlci5WSUVXX1RZUEVfVFdPKSkKICAgICAgICBsaXN0LmFkZChEYXRhTW9kZWwoIkl0ZW0gMyBWaWV3VHlwZSAxIiwgSXRlbUFkYXB0ZXIuVklFV19UWVBFX09ORSkpCiAgICAgICAgbGlzdC5hZGQoRGF0YU1vZGVsKCJJdGVtIDQgVmlld1R5cGUgMiIsIEl0ZW1BZGFwdGVyLlZJRVdfVFlQRV9UV08pKQogICAgICAgIGxpc3QuYWRkKERhdGFNb2RlbCgiSXRlbSA1IFZpZXdUeXBlIDEiLCBJdGVtQWRhcHRlci5WSUVXX1RZUEVfT05FKSkKICAgICAgICBsaXN0LmFkZChEYXRhTW9kZWwoIkl0ZW0gNiBWaWV3VHlwZSAxIiwgSXRlbUFkYXB0ZXIuVklFV19UWVBFX09ORSkpCiAgICAgICAgbGlzdC5hZGQoRGF0YU1vZGVsKCJJdGVtIDcgVmlld1R5cGUgMiIsIEl0ZW1BZGFwdGVyLlZJRVdfVFlQRV9UV08pKQogICAgICAgIGxpc3QuYWRkKERhdGFNb2RlbCgiSXRlbSA4IFZpZXdUeXBlIDEiLCBJdGVtQWRhcHRlci5WSUVXX1RZUEVfT05FKSkKICAgICAgICBsaXN0LmFkZChEYXRhTW9kZWwoIkl0ZW0gOSBWaWV3VHlwZSAyIiwgSXRlbUFkYXB0ZXIuVklFV19UWVBFX1RXTykpCiAgICAgICAgbGlzdC5hZGQoRGF0YU1vZGVsKCJJdGVtIDEwIFZpZXdUeXBlIDIiLCBJdGVtQWRhcHRlci5WSUVXX1RZUEVfVFdPKSkKICAgICAgICBsaXN0LmFkZChEYXRhTW9kZWwoIkl0ZW0gMTEgVmlld1R5cGUgMSIsIEl0ZW1BZGFwdGVyLlZJRVdfVFlQRV9PTkUpKQogICAgICAgIGxpc3QuYWRkKERhdGFNb2RlbCgiSXRlbSAxMiBWaWV3VHlwZSAyIiwgSXRlbUFkYXB0ZXIuVklFV19UWVBFX1RXTykpCgogICAgICAgIHJldHVybiBsaXN0CiAgICB9[/fusion_syntax_highlighter][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”5″ font_size=”18″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]

Output of Multiple View Types

[/fusion_title][fusion_imageframe image_id=”4191|fusion-400″ max_width=”” style_type=”” blur=”” stylecolor=”” hover_type=”none” bordersize=”” bordercolor=”” borderradius=”” align=”center” lightbox=”no” gallery_id=”” lightbox_image=”” lightbox_image_id=”” alt=”” link=”” linktarget=”_self” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” filter_hue=”0″ filter_saturation=”100″ filter_brightness=”100″ filter_contrast=”100″ filter_invert=”0″ filter_sepia=”0″ filter_opacity=”100″ filter_blur=”0″ filter_hue_hover=”0″ filter_saturation_hover=”100″ filter_brightness_hover=”100″ filter_contrast_hover=”100″ filter_invert_hover=”0″ filter_sepia_hover=”0″ filter_opacity_hover=”100″ filter_blur_hover=”0″]https://tutorials.eu/wp-content/uploads/2020/07/Output-4-400×889.png[/fusion_imageframe][fusion_title title_type=”text” rotation_effect=”bounceIn” display_time=”1200″ highlight_effect=”circle” loop_animation=”off” highlight_width=”9″ highlight_top_margin=”0″ before_text=”” highlight_text=”” after_text=”” content_align=”left” size=”2″ font_size=”30″ animated_font_size=”” line_height=”” letter_spacing=”” text_color=”” animated_text_color=”” highlight_color=”” style_type=”none” sep_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=”” fusion_font_variant_title_font=”” fusion_font_family_title_font=”Proxima Nova Regular”]Summary[/fusion_title][fusion_text columns=”” column_min_width=”” column_spacing=”” rule_style=”default” rule_size=”” rule_color=”” animation_type=”” animation_direction=”left” animation_speed=”0.3″ animation_offset=”” hide_on_mobile=”small-visibility,medium-visibility,large-visibility” class=”” id=””]

That’s the basics of RecyclerViews. That’s all you need to know to create RecyclerViews in your app as per your requirements. You can change the kind of layout you want to work in the LayoutManager with other managers such as GridLayoutManager. You can substitute your view as per your app design. The implementation is relatively flexible. Now, you are able to create better views using RecyclerView with Vertical and Horizontal scrolling and as well with GridView. You can also create a view like in the Facebook App which uses Multiple Views in the same RecyclerView. Happy coding.

[/fusion_text][/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]

The form you have selected does not exist.

Enter your email and we will send you the PDF guide:
Enter your email and we will send you the PDF guide