new View.OnClickListener () greyed out ->” No Adapter Attached, skipping Layout” error message


I copied code for a recycler View from a Youtube tutorial but it won’t work out for me. The new View.OnClickListener() is greyed out, with Android Studio suggesting to replace out with lambda. This is the only difference from my code to the one from the tutorial… The App runs through, but doesn’t show the Layout, as I get the error message E/RecyclerView: No adapter attached; skipping layout.

what can I do to fix this?

This is the Adapter class:

package com.example.yourfoodweek;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

public class MealsRecViewAdapter extends RecyclerView.Adapter<MealsRecViewAdapter.ViewHolder>{
    private static final String TAG  "MealsRecViewAdapter";

    private ArrayList <Food> meals  new ArrayList<>();
    private Context mContext;

    public MealsRecViewAdapter(Context mContext) {
        this.mContext  mContext;

    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view  LayoutInflater.from(parent.getContext()).inflate(R.layout.item_meals_list, parent, false);
        return new ViewHolder(view);

    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Log.d(TAG, "onBindViewHolder: Called");

        holder.parent.setOnClickListener(new View.OnClickListener() {
            public void onClick (View v){
                Toast.makeText(mContext, meals.get(position).getName() + "Selected", Toast.LENGTH_SHORT).show();

    public int getItemCount() {
        return meals.size();

    public void setMeals(ArrayList<Food> meals) {
        this.meals  meals;

    public class ViewHolder extends RecyclerView.ViewHolder{

        private CardView parent;
        private ImageView imgFood;
        private TextView txtName;
        public ViewHolder(@NonNull View itemView){
            parent  itemView.findViewById(;
            txtName  itemView.findViewById(;
            imgFood  itemView.findViewById(;


both problems are totally different. first one was suggestion means if you don’t want to apply you can skip it. but i will not suggest to do that.

for example:

(without Lambda)

myButton.setOnClickListener(new View.OnClickListerner(){
    void onClick(View v) {
        // do some stuff related to action    

(with Lambda)

myButton.setOnClickListener(v -> {
   // do some stuff related to action

for other question

no layout manager attached:

if your RecyclerView doesn’t have any LayoutManager attached to it then it will skip cause it will not know how to arrange/show items.

Some LayoutManagers:

  • LinearLayoutManager
  • GridLayoutManager
  • StaggeredGridLayoutManager

if you want to create your own LayoutManager you can do it by just extending class LayoutManager

how to use it:

LinearLayoutManager layoutManager  new LinearLayoutManager();
layoutManager.setOrientation  LinearLayoutManager.HORIZONTAL

no adapter attached

similar to no layout manager this will be shown when no adapter attached to recycler view for this you have to use setAdapter method to set your adapater

for example:

MealsRecViewAdapter adapter  new MealsRecViewAdapter(this);

Answered By – Bhavin

Leave a Comment