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 );
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.
ERROR ANDROID STUDIO E/RecyclerView: No adapter attached; skipping layout
Try to follow the approach:
- 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);
- 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);
}
Kotlin E/RecyclerView: No adapter attached; skipping layout
- there is no setting of
recyclerView var
(usefindViewById(R.id.yourOwnRecycler)
or ViewBinding) - 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()
}
Related Topics
Retrofit:Getting Error ** End of Input At Line 1 Column 1**
Failed to Resolve: Android.Support.Design:28.0.0-Rc02
Notify Observer When Item Is Added to List of Livedata
How to Retry Retrofit Call on Http Errors (401) When Using Rxjava
Dynamically Setting Visibility of Textview in Recyclerview
Eclipse Compiles Successfully But Still Gives Semantic Errors
Html File Input in Android Webview (Android 4.4, Kitkat)
Html File Input Control With Capture and Accept Attributes Works Wrong
Chrome on Android Resizes Font
How to Automatically Open App When Receive Push Notification
How to Disable Viewpager from Swiping in One Direction
Control the Default Music Player of Android or Any Other Music Player
How to Enable/Disable Floatingactionbutton Behavior
How to Clear Livedata Stored Value