Just implemented Recyclerview in my code, replacing Listview.
everything works fine. The objects are displayed.
but logcat says
15:25:53.476 E/RecyclerView﹕ No adapter attached; skipping layout
15:25:53.655 E/RecyclerView﹕ No adapter attached; skipping layout
for the code
ArtistArrayAdapter adapter = new ArtistArrayAdapter(this, artists);
recyclerView = (RecyclerView) findViewById(R.id.cardList);
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
As you can see I have attached an adapter for Recycleview. so why do I keep getting this error?
i have read other questions related to same problem but none helps.
For those who use the
RecyclerView
within a fragment and inflate it from other views: when inflating the whole fragment view, make sure that you bind theRecyclerView
to its root view.I was connecting and doing everything for the adapter correctly, but I never did the binding. This answer by @Prateek Agarwal has it all for me, but here is more elaboration.
Kotlin
Java
It happens when you are not setting the adapter during the creation phase:
Just move setting the adapter into onCreate with an empty data and when you have the data call:
Solved by setting the initialized empty list and adapter at the bottom and calling notifyDataSetChanged when results are fetched.
Just replace above code with this and it should work. What you did wrong is you called setAdapter(adapter) before calling layout manager.
In my case, I was setting the adapter inside
onLocationChanged()
callback AND debugging in the emulator. Since it didn't detected a location change it never fired. When I set them manually in the Extended controls of the emulator it worked as expected.In your
RecyclerView
adapter class, for exampleMyRecyclerViewAdapter
, make a constructor with the following params.mData
is the data that you'll pass to the adapter. It is optional if you have no data to be passed.mInflater
is theLayoutInflater
object that you have created and you use in theOnCreateViewHolder
function of the adapter.After this, you attach the adapter in the MainActivity or wherever you want to on the main/UI thread properly like