No Adapter Attached; Skipping Layout

recyclerview No adapter attached; skipping layout

Can you make sure that you are calling these statements from the "main" thread outside of a delayed asynchronous callback (for example inside the onCreate() method).
As soon as I call the same statements from a "delayed" method. In my case a ResultCallback, I get the same message.

In my Fragment, calling the code below from inside a ResultCallback method produces the same message. After moving the code to the onConnected() method within my app, the message was gone...

LinearLayoutManager llm = new LinearLayoutManager(this);
llm.setOrientation(LinearLayoutManager.VERTICAL);
list.setLayoutManager(llm);
list.setAdapter( adapter );

RecyclerView: No adapter attached; skipping layout - kotlin

I fixed my issue. When using viewBinding/dataBinding, you need to pass dataBinding to the viewHolder. Unfortunately I did not get this as I was just following tutorials that are using synthetic imports. So I changed my Adapter code to the following

RecyclerAdapter.kt

    package com.wildcardev.androidtest1.adapters

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.wildcardev.androidtest1.models.TestDataObj
import com.wildcardev.androidtest1.databinding.ListItemBinding

class RecyclerViewHolder(viewDataBinding: ListItemBinding): RecyclerView.ViewHolder(viewDataBinding.root){
var title: TextView? = viewDataBinding.title
var description: TextView? = viewDataBinding.description
var date: TextView? = viewDataBinding.date
}

class RecyclerAdapter(private var list: ArrayList<TestDataObj>): RecyclerView.Adapter<RecyclerViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder {
Log.d("onCreateView", "INHOLDERcreate")
val binding = ListItemBinding.inflate(LayoutInflater.from(parent.context),parent,false)
return RecyclerViewHolder(binding)
}

override fun onBindViewHolder(holder: RecyclerViewHolder, position: Int) {
Log.d("ADAPTER", "INBINDfunc $holder")
val item = list[position]

holder.title?.text = item.title
holder.description?.text = item.description
holder.date?.text = item.date
}

override fun getItemCount(): Int {
Log.d("COUNT",".getItemCountcalled ${list.size}")
return list.size
}
}

Kotlin E/RecyclerView: No adapter attached; skipping layout

  1. there is no setting of recyclerView var (use findViewById(R.id.yourOwnRecycler) or ViewBinding)
  2. all code accessing views have to be inside onViewCreated
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

recyclerView = view.findViewById(R.id.yourOwnRecycler)

recyclerView?.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)

recyclerView?.adapter = feedAdapter

eventChangeListener()
}

ERROR ANDROID STUDIO E/RecyclerView: No adapter attached; skipping layout

Try to follow the approach:

  1. Create an empty adapter the same time you set LayoutManager for the RecyclerView: Save it as field of your Fragment:
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
userAdapter= new UserAdapter(getContext(), new ArraysList<>(), true);
recyclerView.setAdapter(userAdapter);

  1. When data is ready, populate the adapter and notify:
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
/// origin code here

// reset data in adapter and not re-creating adapter:
userAdapter.setItems(mUsers);
getActivity().runOnUiThread(() -> userAdapter.notifyDataSetChanged());
// instead of userAdapter= new UserAdapter(getContext(), mUsers, true); recyclerView.setAdapter(userAdapter);
}

E/RecyclerView: No adapter attached; skipping layout in fragment android studio using kotlin

onCreateView is where you're meant to inflate a layout for your Fragment to display, and then return it. You're doing that at the end:

return inflater.inflate(R.layout.fragment_v_s, container, false)

But until you do that, the Fragment doesn't have a view! When you try to access view at the start, you're actually calling getView():

Get the root view for the fragment's layout (the one returned by onCreateView), if provided.

So when you do this at the start of onCreateView:

val rv   = view?.findViewById<RecyclerView>(R.id.activeSubsRecycler)

there is no view, so rv is null. So all the setup you're trying to do doesn't happen, because you're null-checking rv before you do them, and since it's null, nothing happens.


When you want to do setup in onCreateView, you need to inflate your view first, then do all your setup on it, and then return that view:

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// get your view inflated
val view = inflater.inflate(R.layout.fragment_v_s, container, false)

// you can make a list like this, if you make your adapter take a
// List<SubscriptionData> instead of an ArrayList<SubscriptionData> (which you should)
val subscription = listOf(
SubscriptionData("ghassan","1000","2002/1/1","2002/1/3"),
SubscriptionData("ameer","2000","2002/1/1","2002/1/3"),
...
)

// Poke around at the stuff in it to get it set up

// This is just a way to null-check once - if it's found (not null),
// this 'let' block will run with the RecyclerView as a variable called 'rv'
view.findViewById<RecyclerView>(R.id.activeSubsRecycler)?.let { rv ->
// don't use an Activity as a context here - just use requireContext,
// you'll have access to one at this point
rv.layoutManager = LinearLayoutManager(requireContext(), RecyclerView.VERTICAL, false)
rv.adapter = SubscriptionAdapter(requireContext(),subscription)
}

// now return the inflated view, which you've set up!
return view
}

Get the idea? You inflate a layout that you're going to pass back, but if you need to set up anything on it, you do that before you return it. (You can be smarter in there, using run or better yet apply, but if you don't know how that would be more elegant don't worry about it!)

The other option is to override onViewCreated to handle your setup stuff - so inflate a view in onCreateView, and that'll get passed into onViewCreated where you can work with it, do setup etc. Whichever you prefer!

E/RecyclerView: No adapter attached; skipping layout for Recycler View in Kotlin Android Project

The view used in creating the recycler view is not same as the view returned
You created a view and that was used to initialize the recycler view,

  var view = inflater?.inflate(R.layout.fragment_impressions, container, false)

instead of returning this same view above you created another view and returned it.

 return inflater.inflate(R.layout.fragment_impressions, container, false)

so the view used in initializing the recycler view is invalid and the recycler view, therefore invalid also.



Related Topics



Leave a reply



Submit