android - android 中的 ListView 计数与适配器计数

标签 android android-layout android-listview android-arrayadapter android-adapter

为什么 listview.getChildCount()adapter.getCount() 返回不同的值?我有一个 onScroll 方法,如果我在其中调用上面的方法,每个方法都会返回不同的值。有谁知道为什么吗?

最佳答案

ListView.getChildCount() 返回屏幕上的 Views 数。 适配器getCount() 返回列表中对象的总数。

getChildCount()

getCount()

你可能在 ArrayAdapter 中有 50 个 String,但目前只有 10 个绘制在屏幕上,所以你的 ListView 算将为 10,但您的 Adapter 计数将为 50。

关于android - android 中的 ListView 计数与适配器计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19142694/

相关文章:

android - 使用 Android BillingClient 2.1 检索应用内购买,返回空列表

android - 在 Java 中使用 Android 的垂直 LinearGradient

android - 实现 HTML 书状分页

javascript - 如何在 expo 应用程序中处理共享 Intent (发送图像)?

java - 聊天布局左、右与包裹背景对齐

android - 从 Activity 布局重叠加载 fragment

android - 如何将recyclerview的项目居中?

java - Android自定义 ListView 在第一个位置显示最后一个项目

android - 如何在填充列表后以编程方式更改列表元素的高度

android - CursorAdapter 动态排序