Todd Hoatson
Todd Hoatson

Reputation: 364

How to Refresh a RecyclerView with new data in onResume()?

In my main activity I have a RecyclerView which is loaded with data from an array list:

protected void onReady(Bundle savedInstanceState) {
    ...
    // create summary item array & populate it based on task item array
    _alData = new ArrayList();
    PopulateDataList();

    _rv = (RecyclerView) findViewById(R.id.rvDataList);
    _li = getLayoutInflater();
    _rv.setLayoutManager(new LinearLayoutManager(this));

    _adapter = new TaskItemAdapter();
    _rv.setAdapter(_adapter);
    ...
}

When the back button is tapped in a second activity, it returns to my main activity, but the RecyclerView is not updated with the new data. So I want to add the following:

public void onResume() {
    super.onResume();  // Always call the superclass method first

    // clear out & re-populate summary list, in case something has changed
    _alData.clear();
    PopulateDataList();

    // *** WHAT GOES HERE...???
}

I don't know how to tell the RecyclerView to re-bind the data from the repopulated list... Any help would be appreciated!

Upvotes: 0

Views: 1873

Answers (1)

diegoveloper
diegoveloper

Reputation: 103361

Add this after populateDataList() :

_adapter.notifyDataSetChanged();

Upvotes: 3

Related Questions