为什么listview.getChildCount()
和adapter.getCount()
会返回不同的值?我有一个onScroll方法,如果我调用上面的方法,每个方法返回不同的值。有谁知道为什么?
答案 0 :(得分:12)
ListView.getChildCount()
会返回屏幕上Views
的数量。 Adapter
s getCount()
会返回列表中的对象总数。
您可能需要50 String
个ArrayAdapter
,但目前只有10个在屏幕上绘制,因此ListView
计数为10,但您的Adapter
} count将是50。
答案 1 :(得分:2)
adapter.getCount()
返回其中包含的总对象数。 listView.getChildCount()
返回此列表视图中显示的观看次数。
适配器使用缓存机制,许多视图被重用,这就是为什么它的数量与adapter.getCount()