Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 539
Ali Bdeir Avatar asked Jan 05 '23 15:01

Ali Bdeir


1 Answers

Use RecyclerView.AdapterDataObserver.

like this:

RecyclerView.Adapter adapter = ...
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
    @Override
    public void onChanged() {
        //Do some task.
    }
});
recyclerView.setAdapter(adapter);
like image 150
nshmura Avatar answered Feb 18 '23 06:02

nshmura