Android RecycleView, after the data is added, the solution is not displayed

Problem description: Activity A contains RecycleView, jump to activity B through the startActivityForResult() function, add data to activity B, and then transfer it to the database.

The problem that the data is not displayed synchronously after the adapter.notifyDataSetChanged() is refreshed in activity A

Reason: Because the List (data set) in Activity A does not contain the newly added data,

Solution: Add the following sentences in the onActivityResult() callback function:
noteDataList.clear();
dm.readFromDB(noteDataList,className);
Collections.reverse(noteDataList); //Reverse
adapter.notifyDataSetChanged();
Description: Clear the original The data in the list can be retrieved from the database according to the conditions again, and then refreshed to display the data synchronously.

Guess you like

Origin blog.csdn.net/qq_41915623/article/details/102265703