6

Let's say I have a RecyclerView, and when it loads data from the databse, I want to do something. I'd imagine it like this:

recyclerView.setOnUpdateListener(new OnUpdateListener() {
            @Override
            public void onChanged() {
                //I do whatever I want
            }
        };

What I've seen:

I've seen this link but the question isn't too clear; and neither is the answer as it doesn't explain what's it doing. And it's pretty old.

I've seen this but it isn't answered yet.


Why?

Because I am loading data from the Database, and I want to show a progress circle while it's loading, and dismiss it when data shows.

Note: I am using a FirebaseRecyclerAdapter.

Community
  • 1
  • 1
Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117

1 Answers1

14

Use RecyclerView.AdapterDataObserver.

like this:

RecyclerView.Adapter adapter = ...
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
    @Override
    public void onChanged() {
        //Do some task.
    }
});
recyclerView.setAdapter(adapter);
nshmura
  • 5,940
  • 3
  • 27
  • 46