I tried to use RecyclerView
with LiveData
basically exactly as described in this question It's really on the beat what I am trying to do, and I imagine it is a quite normal use case. (There is also this question which aligns somewhat with mine )
Goal: Have an update in a table in a RoomDB propagate by LiveData
to be visible as items in a RecyclerView
.
I read up on the paging library and it seems very good but say I do not need to divide into pages for performance. I do not quite understand everything, in that article
Here's some code from the article which I have a comment on which may be relevant to my question:
class MyActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
MyViewModel viewModel = ViewModelProviders.of(this).get(MyViewModel.class);
RecyclerView recyclerView = findViewById(R.id.user_list);
UserAdapter<User> adapter = new UserAdapter();
//Does the following line mean that they set the list on the adapter on each change in the underlying data?
viewModel.usersList.observe(this, pagedList -> adapter.setList(pagedList));
recyclerView.setAdapter(adapter);
}
}
In the observe
they just set the list for the adapter, in the current setup I have notifyDataSetChanged()
(as in the linked question), which i realize is bad. I do not use DiffUtil which I guess is what I get for free in PagedListAdapter
which appeals to me. I would not have arrived at just setting the list of the adapter in the observe
, it seems to me that this is what makes PagedListAdapter
do some heavy lifting.
If i don't want to take advantage of paging should I still use the paging components? (to get it to do DiffUtil things for me?)
How do I achieve the Goal as smoothly as possible with architecture components?
Edit: Also noticed paging component is in alpha at the moment