1. 程式人生 > android教程 > android開發之ListView.getCount()與ListView.getChildCount()區別

android開發之ListView.getCount()與ListView.getChildCount()區別

①.
ListView.getCount()方法;實際上是AdapterView.getCount(),返回的是其Adapter.getCount()返回的值.也就是”所包含的Item總個數”.

②.
ListView.getChildCount();實際上是ViewGroup.getChildCount(),返回的是顯示層面上的”所包含的子View個數”.

二者有什麼不同?當ListView中的Item比較少無需滾動即可全部顯示時,二者是等價的;當Item個數較多需要滾動才能瀏覽全部時,getChildCount()和getCount()想比較,其中getChildCount()返回的是當前可見的Item個數.