1.加頭尾部
(1)定自義一個xml布局 my_headview.xml
在Activity類里找到這個自定義布局,並添加到頭部
LinearLayout hearderViewLayout = (LinearLayout) LayoutInflater.(
xwActivity.this).inflate(R.layout.my_headview, null);
listview.addHeaderView(hearderViewLayout);
(2)定自義一個xml布局 my_footview.xml
LinearLayout footViewLayout = (LinearLayout) LayoutInflater.(
xwActivity.this).inflate(R.layout.my_footview, null);
listview.addFooterView(footerViewLayout);
(3)重視事務
listview必然會有Adapter,參加頭尾部,必須在參加Adapter之前!
listview.addHeaderView(hearderViewLayout);
listview.addFooterView(footerViewLayout);
listview.setAdapter(myAdapter);
1.加上拉到尾部的監聽件件
listview.setOnScrollListener(new OnScrollListener() {
public void onScrollStateChanged(AbsListView view, int scrollState) {
switch (scrollState) {
case OnScrollListener.SCROLL_STATE_IDLE: // 當不遷移轉變時
// 斷定遷移轉變到底部
if (view.getLastVisiblePosition() == (view.getCount() - 1)) {
//在這里添加操縱
}
break;
}
}
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
}
});
文章引自:http://blog.csdn.net/wangwei_cq/article/details/9383759