listview count vs adapter count in android

不打扰是莪最后的温柔 提交于 2019-12-06 08:51:07

问题


Why do listview.getChildCount() and adapter.getCount() return different values? I have an onScroll method and from within it, if I call the methods above, each return different values. Does anyone know why?


回答1:


ListView.getChildCount() returns the number of Views on the screen. Adapters getCount() returns the total number of objects in your list.

getChildCount()

getCount()

You might have 50 Strings in say an ArrayAdapter but only 10 are drawn on the screen at the current moment so your ListView count will be 10 but your Adapter count will be 50.




回答2:


adapter.getCount() returns total objects count contained in it. listView.getChildCount() return number of views showed in this listview. Adapter uses caching mechanism, and a lot of views are reused, that's why it's number differs from that shown in adapter.getCount()



来源:https://stackoverflow.com/questions/19142694/listview-count-vs-adapter-count-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!