'How can I add only the new items of the JSON API without duplicating the existed items?

I want to make an auto refreshing system for my android application. I use a JSON API in order to get the posts. Here is what I did:

handler.postDelayed( runnable = new Runnable() {
            public void run() {
                //do your function;
                ReadPosts();
                readSaves();
                postsAdapter.notifyDataSetChanged();
                postsAdapterS.notifyDataSetChanged();
                handler.postDelayed(runnable, apiDelayed);
            }
        }, apiDelayed);

So, what I want is every time the handler refreshes to be added only the new posts that are added to the JSON but not to duplicate each post every time it is refreshed. Is there a way to do that?



Solution 1:[1]

I understand that you want the list to be updated from time to time. First create a public void clear() method in which you call the method that performs the data load. It should be noted that at the beginning of the method that makes the data call you will have to clean the list, that is, you will use [list].clear().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Henry Ecker