0
我正嘗試使用LoadManager將更多項加載到列表視圖中。但每次我的listview更新,我看不到舊的結果。我怎樣才能看到所有的結果,並加載到底部?如何使用LoaderManager將更多項加載到ListView中
private OnScrollListener onScrollListener() {
return new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
int threshold = 1;
int count = listView.getCount();
if (scrollState == SCROLL_STATE_IDLE) {
// is it good condition to load new data dynamically?
if (listView.getLastVisiblePosition() >= count - threshold) {
// startIndex is a start point for the query
// default value is 0
startIndex += 10;
// this method format the URL using URI.Builder and change startIndex
formatUrl(false, keywords, startIndex);
// Clear the adapter
mAdapter.clear();
// I think the problem is here?! But how to fix it?!
getLoaderManager().restartLoader(LOADER_ID, null, MainActivity.this);
}
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
}
};