Q:

Can't inflate Views in RecyclerView

I am a noob in Android Development, and I was trying to build a custom sidebar today.
I used a view with 2 imageViews, and I was trying to inflate them multiple times with multiple icons, which I did using a custom class. Here is the view code:
Side_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:src="@drawable/icn"
        android:layout_height="48dp"
        android:tint="#afafaf"
        android:id="@+id/menu_icon"
        />

    <ImageView
        android:layout_width="8dp"
        android:layout_height="8dp"
        android:id="@+id/menu_selector"
        android:src="@drawable/selector"
        android:layout_gravity="center_horizontal"
        />

</LinearLayout>

Here is my custom class:
public class Item
{
    private int icon, code;
    private boolean isSelected;

    public Item(int icon, int code)
    {
        this.icon = icon;
        this.code = code;
    }

    public int getIcon()
    {
        return icon;
    }

    public void setIcon(int icon)
    {
        this.icon = icon;
    }

    public int getCode()
    {
        return code;
    }

    public void setCode(int code)
    {
        this.code = code;
    }

    public boolean isSelected()
    {
        return isSelected;
    }

    public void setSelected(boolean selected)
    {
        isSelected = selected;
    }

    public Item(int icon, int code, boolean isSelected)
    {
        this.icon = icon;
        this.code = code;
        this.isSelected = isSelected;
    }
}

I used this code for assigning data to this class:
public class MenuUtils
{
    public static final int HOME = 0, EDU = 1, CONTACT = 2, PROJECTS = 3;

    public static List<Item> getList()
    {
        List<Item> list = new ArrayList<>();

        list.add(new Item(R.drawable.icn1, HOME, true));
        list.add(new Item(R.drawable.icn2, EDU, true));
        list.add(new Item(R.drawable.icn3, CONTACT, true));
        list.add(new Item(R.drawable.icn4, PROJECTS, true));

        return list;
    }

}

Here is the code for my adapter:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder>
{
    List<Item> list;

    public MyAdapter(List<Item> list)
    {
        this.list = list;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
    {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.side_bar, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position)
    {
        holder.icon.setImageResource(list.get(position).getIcon());

        if (list.get(position).isSelected()) holder.selected.setVisibility(View.VISIBLE);
        else holder.selected.setVisibility(View.INVISIBLE);
    }

    @Override
    public int getItemCount()
    {
        Log.i("List Size", list.toString());
        return list.size();

    }

    public class MyViewHolder extends RecyclerView.ViewHolder
    {
        ImageView icon, selected;

        public MyViewHolder(@NonNull View itemView)
        {
            super(itemView);

            icon = (ImageView) itemView.findViewById(R.id.menu_icon);
            selected = (ImageView) itemView.findViewById(R.id.menu_selector);

        }
    }
}

The method used for setting up the sidebar:
private void setMenu()
    {
        menu = findViewById(R.id.menu_holder);

        List<Item> items = MenuUtils.getList();

        MyAdapter adapter = new MyAdapter(items);

        menu.setLayoutManager(new LinearLayoutManager(this));
        menu.setAdapter(adapter);
    }

On logging, I see that the list has 4 data items, but when inflated, only one appears.
Why so?
Please help.

A:

I guess each item of recycle view is taking the entire screen that's why you can only see one item. Adjust the LinearLayout height and width, as-
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
......
</LinearLayout>

If you want the each item to take entire screen width use
android:layout_width="match_parent"

or vice-versa.
Happy coding !!!

