Android RecyclerView LayoutManager Exception

后端 未结 2 1403
日久生厌
日久生厌 2021-02-20 04:21

Hi I\'m having an issue with the new Android Lollipop RecyclerView

It keeps crashing with the following exception:

Attempt to inv         


        
相关标签:
2条回答
  • 2021-02-20 04:55

    Add the following code:

        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
    

    Before adding adapter:

    recyclerView.setAdapter(adapter);
    
    0 讨论(0)
  • 2021-02-20 04:56

    In the android Api level 22 it will not give the error. Instead it skips the layout if the Adapter is not found.

    By showing the warning:

    RecyclerView﹕ No adapter attached; skipping layout

    But your app will not crash and runs, but recyclerView doesn't shown.

    0 讨论(0)
提交回复
热议问题