1

I have a recycler view which is fetching data from the server and it is working fine. But I'm getting an error "No adapter attached; skipping layout" which I know I can solve this by setting an empty adapter. But this is important? It works without an empty adapter also.

Edit:-

I know how to fix that. I'm asking it is working without setting empty adapter. Why setting empty adapter is important?

My method which is setting up the recycler View.

private void setUpCategoryRecyclerView(List<Category> allCategories) {

    final RecyclerView categoryListRecyclerView = (RecyclerView) getViewById(R.id.recyclerView);
    final CategoryAdapter categoryAdapter = new CategoryAdapter(allCategories, false);

    categoryAdapter.setOnItemClickListener(new CategoryAdapter.clickListener() {

        @Override
        public void onItemClick(int position, View v) {

            final TextView CategoryName = v.findViewById(R.id.categoryName);
            final Bundle bundle = new Bundle();  // Payload for next fragment
            bundle.putString(CATEGORY, CategoryName.getText().toString());
            FragmentsCallBack.CallBack(bundle);
        }
    });
    categoryListRecyclerView.setLayoutManager(new LinearLayoutManager(context));
    categoryListRecyclerView.setAdapter(categoryAdapter);
    enableSearch(allCategories, categoryAdapter);
}
OhhhThatVarun
  • 3,981
  • 2
  • 26
  • 49
  • 1
    Possible duplicate of [recyclerview No adapter attached; skipping layout](https://stackoverflow.com/questions/29141729/recyclerview-no-adapter-attached-skipping-layout) – ADM Feb 25 '19 at 12:14
  • please add some codes – Basi Feb 25 '19 at 12:15
  • @ADM My question is different. I know how to fix that I'm just asking why it is important. Please read the whole question. – OhhhThatVarun Feb 25 '19 at 12:15
  • I read it .. And i think its just a warning . Not important. You can skip this by setting adapter and `LayoutManager` same time or you can use a Empty dataset with adapter . – ADM Feb 25 '19 at 12:17
  • @ADM See update – OhhhThatVarun Feb 25 '19 at 12:20
  • `Adapter` does not play any role in this `LayoutManager` does . If you set `LinearLayoutManager` without setting adapter then you will get this error log . – ADM Feb 25 '19 at 12:22

1 Answers1

1

Since it a warning, You can ignore that but developers of SDK are throwing this warning it means you should handle it. Though it will not harm or crash your app it's advisable to get rid of it as clean logcat helps you to debug faster and efficiently.

In case you don't have data initially, just set an empty adapter first, update it as soon as you have the data.

Firdous nath
  • 1,487
  • 1
  • 14
  • 38