krentm
krentm

Reputation: 142

Android Recycler view not updating

I have a recycler view that fills with data at the application's start. It fills well everytime, but the recycler view doesn't update everytime. Clicking the action bar to open the keyboard refreshes it.

I also notify the recycler view for update after all of the data has finished loading.

  1. How should I update/refresh it?
  2. Is recycler view not updating a bug or something?

I'm gonna add code and XML layouts if needed.

refresh/notify code:

// Inflate
new java.util.timer().schedule(
    () -> {
        runOnUiThread(()->{
            adapter.notifyDataSetChanged();
        });

    }, 1000
);

Upvotes: 1

Views: 452

Answers (1)

casillas
casillas

Reputation: 16813

Check following example to refresh recyclerview in every 1 second.

Handler timerHandler;
timerHandler = new Handler();

Runnable timerRunnable = new Runnable() {
    @Override
    public void run() {
        adapter.notifyDataSetChanged();
        timerHandler.postDelayed(this, 1000);
    }
};

timerHandler.postDelayed(timerRunnable, 1000);

Upvotes: 2

Related Questions