how to read all value from room data base and show into recyclerview?

前端 未结 1 1314
不思量自难忘°
不思量自难忘° 2020-12-12 07:10

I am using room database for storing json data from URL its working fine but while accessing data from data base to show on recyclerview its give one result at time and if i

1条回答
  •  被撕碎了的回忆
    2020-12-12 07:38

    Follow this or this

    You didn't add LiveData in your dao. Add livedata and it will automatically return the list for you. However

    In your dao

    @Query("select * from table_name")
    public LiveData> getAll();
    

    In your activity or fragment

     yourViewModel.getAll().observe(this, new Observer>() {
            @Override
            public void onChanged(@Nullable List models) {
                adapter.addAll(models);
            }
        });
    

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