所以我在一个片段上使用了来自 commonsware 的无限适配器,我遇到的问题是每次我在适配器等待完成加载一些数据时旋转,都会再次调用 cacheInBackground 方法。适配器的初始化是在片段的 onActivityCreated 方法上调用的,那么我怎样才能简单地恢复第一次调用 cacheInBackground 方法的结果呢?
IpdmsEndlessAdapter endAdapt= new IpdmsEndlessAdapter(getActivity(),adapter,R.layout.list_loading_row){
@Override
protected boolean cacheInBackground() throws RequestException{
tempList.clear();
List<MyProcessDTO> myPRocs;
myPRocs = new MyprocessesManager(getActivity()).getMyProcessesFromServer(processListPage);
if(myPRocs!=null){
tempList.addAll(myPRocs);
}else
return false;
//return true if there's more data do return
//return false if there was an error or there's no more data
return myPRocs.size()>=10;
}
@Override
protected boolean onException(View pendingView, Exception e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
return false;
}
@Override
protected void appendCachedData() {
@SuppressWarnings("unchecked")
GenericMenuAdapter a=(GenericMenuAdapter)getWrappedAdapter();
for(MyProcessDTO myProcessDTO:tempList){
a.add(new IpdmsMobileMenuItemListDTO(myProcessDTO.getNrprocesso(), myProcessDTO.getEtapa(), 0, myProcessDTO));
}
processListPage++;
}
};
actualListView.setAdapter(endAdapt);
问候,