Data is coming twice after refreshing recyclerview

421 Views Asked by At

I'm developing an app by using sliding tab.After refreshing the data in one tab and while i'm going to another tab the text is coming twice.How to solve this problem. I'm using the adapter class.

Here is my code.

   mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swifeRefresh);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            AsyncFetch();

            upcomingJobs.clear();
            upcomingJobs.addAll(upcomingJobs);

            // fire the event
            uAdapter.notifyDataSetChanged();


            // uAdapter.notifyDataSetChanged();
        }
    });
    mSwipeRefreshLayout.setRefreshing(false);
1

There are 1 best solutions below

0
Hugo Houyez On

Add this function in your adapterClass:

public void clearData() {
    int size = this.your_list.size();
    if (size > 0) {
        for (int i = 0; i < size; i++) {
            this.your_list.remove(0);
        }

        this.notifyItemRangeRemoved(0, size);
    }
}

And then call it at the start of your

onRefresh()