ListView
有标题视图并注册AbsListView.OnScrollListener
以加载更多项目。
为ListView添加了标题视图:
headerView = new LinearLayout(getActivity());
headerView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200));
listView.addHeaderView(headerView);
OnScrollListener的回调:
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
...
}
检查onScroll
上的参数时,firstVisibleItem
值很奇怪,并且在向下滚动后突然以 -1 返回。
logcat的:
firstVisibleItem= 0 , visibleItemCount= 5 , totalItemCount= 22
firstVisibleItem= 0 , visibleItemCount= 5 , totalItemCount= 22
firstVisibleItem= 0 , visibleItemCount= 5 , totalItemCount= 22
firstVisibleItem= -1 , visibleItemCount= 6 , totalItemCount= 22
firstVisibleItem= -1 , visibleItemCount= 6 , totalItemCount= 22
有谁知道原因?