【发布时间】:2020-05-17 19:26:59
【问题描述】:
让我解释一下发生了什么。我有一个片段,在它的 onCreateView() 中,我将适配器设置为没有任何项目的 recyclerview..
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
downloadsList = new ArrayList<>();
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
downloadsRecyclerview.setLayoutManager(linearLayoutManager);
downloadsList.clear();
downloadAdapter = new DownloadAdapter(context, downloadsList);
downloadsRecyclerview.setAdapter(downloadAdapter);
}
现在奇怪的部分是每当我将项目添加到downloadsList(基本上是一个 ArrayList )时,我的 recyclerview 就会使用 downloadsList 上的可用内容进行更新。我什至没有调用 notifyDataSetChanged() 或再次设置新适配器...任何帮助..
【问题讨论】:
-
但在将其设置为适配器后,我仍然可以向 downloadsList 添加任何内容..
-
显示您添加项目的代码,以及您的适配器代码。
标签: android android-fragments android-recyclerview