Hello All:
RecyclerView is introduced with Android L and is also available with AppCompat library. RecyclerView provides better layout option and performance as compared to ListView. However, in this post I will share one of the possible solutions to a problem which occurs with RecyclerView.
Often in our application we rely on network data to be populated in our views. With RecyclerView one problem occurs when the data is not available during initialization.
In the logcat, you can often see following error.
One way to fix this issue is to attach an empty adapter to the RecyclerView
Hope this helps. Let me know if you know any other way of fixing the issue.
RecyclerView is introduced with Android L and is also available with AppCompat library. RecyclerView provides better layout option and performance as compared to ListView. However, in this post I will share one of the possible solutions to a problem which occurs with RecyclerView.
Often in our application we rely on network data to be populated in our views. With RecyclerView one problem occurs when the data is not available during initialization.
In the logcat, you can often see following error.
recyclerview No adapter attached; skipping layout
One way to fix this issue is to attach an empty adapter to the RecyclerView
void initializeRecyclerView() { recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView); recyclerView.setAdapter(new SampleAdapter(getCurrentActivity())); recyclerView.setLayoutManager(new LinearLayoutManager(getCurrentActivity())); recyclerView.setHasFixedSize(true); }
Call this method in OnCreateView or OnCreate methods.
Hope this helps. Let me know if you know any other way of fixing the issue.
Thanks for printing this post. Hope you liked it.
Keep visiting and sharing.
Thanks,
Ashwani.
Keep visiting and sharing.
Thanks,
Ashwani.
Why does this problem occur? any docs supporting this?
ReplyDeletethis is error should come while using retrofit API
ReplyDeleteWould this be applicable to volley?
ReplyDeletewould this be applicable to volley?
ReplyDelete