Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recycler view showing single item

People also ask

How do I display a list in RecyclerView?

In this step, we will create a new layout file for the single list item view. Go to app > res > layout > right-click > New > Layout Resource File and name it as list_item. list_item. xml contains an ImageView and a TextView which is used for populating the RecyclerView.

What is nested recycler view?

A nested RecyclerView is an implementation of a RecyclerView within a RecyclerView. An example of such a layout can be seen in a variety of apps such as the Play store where the outer (parent) RecyclerView is of Vertical orientation whereas the inner (child) RecyclerViews are of horizontal orientations.


Don't use match_parent for height for your item view. One item fills whole screen vertically so you don't see another.


when you are creating row.xml for recyclerview should follow these things:

  1. Always use "wrap_content" for the height of the row otherwise in "match_parent" it will occupy the whole screen for a single row.

  2. You can also take the height in dp.


My mistake was I accidentally used:

LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)

instead of:

LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)

Try changing the layout used in your item view to FrameLayout. Here is an example.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item"
    android:layout_width="match_parent"
    android:layout_height="?listPreferredItemHeight"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?selectableItemBackground">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"/>
</FrameLayout>

content_main.xml as follows

android:layout_width="match_parent"
android:layout_height="match_parent"

IN row_list.xml file make following changes

android:layout_width="match_parent"
android:layout_height="wrap_content"

I make above changes it runs.