我正在使用这个 PullToRefresh 代码:
https://github.com/erikwt/PullToRefresh-ListView
XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/bg_listview_grey" >
<eu.erikw.PullToRefreshListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="6dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="6dp"
android:divider="@color/bg_listview_grey"
android:dividerHeight="6dp"
android:drawSelectorOnTop="true"
android:scrollbars="none" />
</RelativeLayout>
ListView相关的活动代码:
listView = (PullToRefreshListView) view
.findViewById(R.id.feedListView);
footerView = inflater.inflate(R.layout.footer, listView, false);
feedListView.addFooterView(footerView);
listAdapter = new DefaultFeedAdapter((Activity) getSherlockActivity(),
list_items, listView);
listView.setAdapter(listAdapter);
feedListView.setOnScrollListener(new OnScrollListener() {
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// what is the bottom item that is visible
int lastInScreen = firstVisibleItem + visibleItemCount;
// is the bottom item visible & not loading more already ? Load
// more !
if ((lastInScreen == totalItemCount) && totalItemCount >= 3
&& !LoadingNextData && !noMoreItems) {
lastId = listAdapter.values.get(totalItemCount - 3).id;
LoadingNextData = true;
new GetNewItems().execute("" + lastId);
}
}
});
listView.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
new RefreshList().execute("");
}
});
private class RefreshFeed extends AsyncTask<String, Void, String> {
//adds items at the top of the list if there are any.
//But even without any new items ie.. without touching
//the listView, it breaks.
}
问题是:
在加载时,它破坏了底部 listView 的 40%,当它被加载时,它破坏了 listView 的大约 20%,最后显示了整个 listView。
我错过了什么吗?请帮忙。
谢谢你。