该应用程序的目的是在用户向下滚动并更新现有ListView时获取更多数据。
处理用户滚动的代码段是:
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
int totalVisible = firstVisibleItem + visibleItemCount;
if (view.getAdapter() != null &&
(totalVisible >= totalItemCount) &&
totalItemCount != priorFirst &&
visibleItemCount != totalItemCount) {
Log.v("MyActivity", "onListEnd, extending list");
priorFirst = totalItemCount;
//params is array of values passed to business layer for data fetch
String[] params = builder.toString().split("&");
UIHandler uiHandler = new UIHandler(this, getParent());
//start async task
EnquiriesRunner enquiriesRunner = new EnquiriesRunner(uiHandler);
enquiriesRunner.execute(params);
}
在后台,它会调用业务层。
protected ExceptionHandler<Object> doInBackground(String... params) {
Object obj = enquiriesCaller.getEnquiries(params);
return new ExceptionHandler<Object>(obj);
}
将结果数据传递给UI处理程序,使用自定义适配器将其呈现给listView。
ListView enquiryView = (ListView) ((Activity) childContext).findViewById(R.id.enquiryListView);
CustomAdapter adapter = new CustomAdapter(childContext, msg.obj);
enquiryView.setAdapter(adapter);
msg.obj是包装到Object中的搜索结果。这将被转换为适配器中所需的POJO引用。
如您所见,每次使用新数据集替换listView时。任何人都可以建议更新现有List的可能解决方案吗?
提前致谢!
答案 0 :(得分:1)