Error Android Studio E/recyclerview: No Adapter Attached; Skipping Layout
I need help, i have an error, that is this: E/RecyclerView: No adapter attached; skipping layout CODE: public View onCreateView(LayoutInflater inflater, ViewGroup container,
Solution 1:
I'm going to argue the case that you can simply ignore the warning as that's all it is. Your recycler adapter does get created and applied to the RecyclerView when you have some data to display.
Solution 2:
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(newLinearLayoutManager(getContext()));
userAdapter= newUserAdapter(getContext(), new ArraysList<>(), true);
recyclerView.setAdapter(userAdapter);
- When data is ready, populate the adapter and notify:
publicvoidonDataChange(@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);
}
Solution 3:
For kotlin(Fragment):
recyclerView.layoutManager=LinearLayoutManager(context)
Post a Comment for "Error Android Studio E/recyclerview: No Adapter Attached; Skipping Layout"