android getView方法不執行的一個原因是佈局檔案中沒有給列表顯示的位置
一個原因是佈局檔案中,沒有給列表顯示的位置。
例如:下面的佈局
<com.xxx.view.BaseListView
android:id="@+id/list_find"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@android:color/transparent"
android:divider="@drawable/base_horizontal_line"
android:dividerHeight="1dp"
android:fadingEdgeLength="0dp"
android:fastScrollEnabled="true"
android:paddingBottom="10dp" />
<com.xxx.view.BaseListView
android:id="@+id/list_article"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@android:color/transparent"
android:divider="@drawable/base_horizontal_line"
android:dividerHeight="1dp"
android:fadingEdgeLength="0dp"
android:fastScrollEnabled="true"
android:paddingBottom="10dp" />
第一個名字是list_find的View高度是match_parent,已經把空間佔滿,導致第一個名字為list_article的View沒有顯示的空間,這樣就導致這個View不執行getView方法,資料顯示不出來。
另外如果view的getCount結果為0,也不執行getView方法。