listview count vs android中的适配器数量

时间:2013-10-02 17:07:26

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

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

2 个答案:

答案 0 :(得分:12)

ListView.getChildCount()会返回屏幕上Views的数量。 Adapter s getCount()会返回列表中的对象总数。

getChildCount()

getCount()

您可能需要50 StringArrayAdapter,但目前只有10个在屏幕上绘制,因此ListView计数为10,但您的Adapter } count将是50。

答案 1 :(得分:2)

adapter.getCount()返回其中包含的总对象数。 listView.getChildCount()返回此列表视图中显示的观看次数。 适配器使用缓存机制,许多视图被重用,这就是为什么它的数量与adapter.getCount()

中显示的数字不同的原因