recyclerview No adapter attached; skipping layout

后端 未结 30 3141
走了就别回头了
走了就别回头了 2020-11-21 04:51

Just implemented RecyclerView in my code, replacing ListView.

Everything works fine. The data is displayed.

But error messages are

30条回答
  •  忘了有多久
    2020-11-21 05:10

    I lost 16 minutes of my life with this issue, so I'll just admit to this incredibly embarrassing mistake that I was making- I'm using Butterknife and I bind the view in onCreateView in this fragment.

    It took a long time to figure out why I had no layoutmanager - but obviously the views are injected so they won't actually be null, so the the recycler will never be null .. whoops!

    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    
        @Override
    public View onCreateView(......) {
        View v = ...;
        ButterKnife.bind(this, v);
        setUpRecycler()
     }
    
    public void setUpRecycler(Data data)
       if (recyclerView == null) {
     /*very silly because this will never happen*/
           LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
           //more setup
           //...
        }
        recyclerView.setAdapter(new XAdapter(data));
    }
    

    If you are getting an issue like this trace your view and use something like uiautomatorviewer

提交回复
热议问题