我有一个列表,任何用户都可以随时更新.该列表由 RecyclerView 显示.我想实时更新此列表,以便用户获得更好的用户体验,因为用户无需执行多次刷新.现在的问题是,如何实时更新此列表?
I have a list which can be updated any time by any user. The list is showed by in a RecyclerView. I want to update this list in real time so that user can get a better user experience because user need not to perform refresh several times. Now question is, how can I update this list in real time ?
推荐答案使用RecyclerView,您可以使用适配器更新单个项目,项目范围或整个列表.
With RecyclerView you can either update a single item, item range or the whole list with the adapter.
您必须使用RecyclerView适配器的方法,例如adapter#notifyItem***或adapter#notifyDataSetChanged()(这将更新RecyclerView中的整个项目列表).
You have to use RecyclerView adapter's method like adapter#notifyItem*** or adapter#notifyDataSetChanged() (this will update the whole list of items in the RecyclerView).
class RVAdapter extends ...{ List<?> itemList; public void updateList (List<Object> items) { if (items != null && items.size() > 0) { itemList.clear(); itemList.addAll(items); notifyDataSetChanged(); } } }更多推荐
如何实时更新RecyclerView?
发布评论