Ali Bdeir
Ali Bdeir

Reputation: 4375

Is there an existing method that listens for a RecyclerView item change?

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.

Upvotes: 6

Views: 6642

Answers (1)

nshmura
nshmura

Reputation: 6010

Use RecyclerView.AdapterDataObserver.

like this:

RecyclerView.Adapter adapter = ...
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
    @Override
    public void onChanged() {
        //Do some task.
    }
});
recyclerView.setAdapter(adapter);

Upvotes: 15

Related Questions