Android : Android refresh Recyclerview delayed

on Saturday, March 28, 2015


I have a simple layout with a recyclerview. In the onCreateView method I set up the Recyclerview:



@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_overview, container, false);
recyclerView = (RecyclerView) rootView.findViewById(R.id.rv_overview);
list = new ArrayList<>();
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);

list = getOverviewList(getActivity());
adapter = new OverviewRecyclerAdapter(getActivity(), list);
recyclerView.setAdapter(adapter);
final Context context = getActivity();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
list =getOverviewList(context);
adapter.notifyDataSetChanged();
}
}, 1000);
return rootView;
}


As you can see the Recyclerview needs to be refreshed a second after the view is creted. I tried to achieve thsi with a Handler. But the code within the Handler does not refresh the Recyclerview. But obviously it should.


0 comments:

Post a Comment