MohanRaj MohanRaj - 1 year ago 60
Android Question

Empty Recycler view is not getting updated with new data

I intialize my recycler view adapter with an empty arraylist initially.
Then later once I fetch data from API I try to update the adapter by calling

but none of call back methods in my adapter is getting fired

void initRecyclerView()
myList = new ArrayList<>();
myRecyclerAdapter = new myRecyclerAdapter(getActivity(), myList, "");
linearLayoutManager = new LinearLayoutManager(getActivity());

After getting data from API I just update the adapter as follow :

void updateRecyclerView(ArrayList<Data> newList)
if (myList.isEmpty())

Answer Source

I made a costliest mistake and ponder around something else instead of looking it at different aspect.

I had SwipeRefreshLayout that wraps RecyclerView.

I should've just use setRefreshing(false) once data downloaded through API call. Instead I used setVisibility(VIEW.GONE) on mymSwipeRefreshLayout`.

This visibility change of SwipeRefreshLayout impacted RecyclerView within.

I hope none will do this mistake. Perhaps someone might come across this tiniest mistake so I Mark my answer as accepted answer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download