LoginSignup
0
1

RecyclerViewで何も表示されない時に確認すべきこと。

Posted at

何度もハマるので自分の備忘のために記入。

RecyclerViewに何も表示されない場合、以下の点を確認しましょう。

RecyclerViewにlayoutManagerを設定する。

layoutManagerに何も設定しないと、何も表示されません。
view Bindingを使用している場合、以下のような感じで設定する。

XXXActivity.kt
    binding.recyclerView.layoutManager = LinearLayoutManager(this)

コードで設定する代わりにlayout editorで設定しても良い。

(表示後にデータ更新している場合) nofityDataSetChanged() を呼ぶ

RecyclerViewAdapterが参照しているデータが変わった場合、表示を更新するためには

notifyDataSetChanged()

などを呼び出す必要がある。
(変更内容によっては行単位の更新を反映するメソッドのほうが適切な場合もあります。)

以上

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1