recyclerview No adapter attached; skipping layout

后端 未结 30 3731
走了就别回头了
走了就别回头了 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条回答
  •  萌比男神i
    2020-11-21 05:23

    i have this problem , a few time problem is recycleView put in ScrollView object

    After checking implementation, the reason appears to be the following. If RecyclerView gets put into a ScrollView, then during measure step its height is unspecified (because ScrollView allows any height) and, as a result, gets equal to minimum height (as per implementation) which is apparently zero.

    You have couple of options for fixing this:

    1. Set a certain height to RecyclerView
    2. Set ScrollView.fillViewport to true
    3. Or keep RecyclerView outside of ScrollView. In my opinion, this is the best option by far. If RecyclerView height is not limited - which is the case when it's put into ScrollView - then all Adapter's views have enough place vertically and get created all at once. There is no view recycling anymore which kinda breaks the purpose of RecyclerView .

    (Can be followed for android.support.v4.widget.NestedScrollView as well)

提交回复
热议问题