为什么 listview.getChildCount()
和 adapter.getCount()
返回不同的值?我有一个 onScroll 方法,如果我在其中调用上面的方法,每个方法都会返回不同的值。有谁知道为什么吗?
最佳答案
ListView.getChildCount()
返回屏幕上的 Views
数。 适配器
的getCount()
返回列表中对象的总数。
你可能在 ArrayAdapter
中有 50 个 String
,但目前只有 10 个绘制在屏幕上,所以你的 ListView
算将为 10,但您的 Adapter
计数将为 50。
关于android - android 中的 ListView 计数与适配器计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19142694/