I am attempting to load more items at the end of listview. upon scolling to the end of the listview only the progressbar is shown but more items is never added to the listview.
CustomAdapter adapter; //initialize adapter
@Override
protected Integer doInBackground(Void... params) {
return this.parseData();
}
//called in onpost execute
adapter=new CustomAdapter(c,spacecrafts);
lv.setAdapter(adapter);
lv.setOnScrollListener(new AbsListView.OnScrollListener() {
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if(firstVisibleItem+visibleItemCount == totalItemCount && totalItemCount!=0)
{
if(flag_loading == false)
{
flag_loading = true;
lv.setAdapter(adapter);
expand = expand + 5;
}
}
}
});
Please what could be wrong
不要清除您的列表,然后尝试。
spacecrafts.clear();
Try initialize the Adapter and ArrayList in your class body like bellow:
ArrayList<Spacecraft> spacecrafts = new ArrayList<Spacecraft>();
CustomAdapter adapter = new CustomAdapter(spacecrafts);
Then call this code inside onCreate method
lv.setAdapter(adapter);
And after that when you added new items to the list you can notify the adapter by calling:
adapter.notifyDataSetChanged();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.