recyclerView.getChildCount()每次都返回不同数量的子进程

Shi*_*ani 4 android android-recyclerview expandablerecyclerview

我创建了一个RecyclerView包含动态EditText字段的文件.EditText编辑字段中的值时,我需要在单击按钮时保存它们.我正在使用recyclerView.getChildCount()每次都给出不同数字的子计数.

小智 15

RecyclerView执行其名称所指示的内容.它回收了视图.假设您有1000个条目的列表,但在任何给定时间,其中3-4个条目显示在屏幕上.RecyclerView的适配器始终包含所有这些子节点,因此调用recyclerView.getAdapter().getItemCount();将返回1000.

但是,RecyclerView仅保留一些显示的项目并且"显示"接近显示,因此recyclerView.getChildCount()将返回较小且非常量的值.对于大多数应用程序,您应该使用适配器提供的方法.


R. *_*ski 5

RecyclerView的子级是指行数?

然后,我建议调用适配器的方法。呼叫:

recyclerView.getAdapter().getItemCount();
Run Code Online (Sandbox Code Playgroud)