【文件属性】:
文件名称:ListView延迟加载
文件大小:81KB
文件格式:ZIP
更新时间:2015-07-23 15:08:07
ListView 延迟加载
ListView 延迟加载
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new LongOperation(this,new Excution(){
@Override
public void longExcute(){
lazyData = new LazyListData(UIData.getTotalRows(),
UIData.getListRows(0,LazyAdapter.PAGE_SIZE_LAZY-1));
SystemClock.sleep(3000);//休息3秒,模拟网络延迟
}
@Override
public void uiUpdate(){
setContentView(R.layout.empty_list);
setListAdapter(new LazyAdapter(
LazyLoadingActivity.this,
R.layout.row,//list中的行布局
lazyData.getListData(),//得到数据
lazyData.getTotalRows(),//得到总行数
new LazyLoading(){
@Override
public void cacheNextPageData(int startIndex, int endIndex) {//加载下一页
Log.d(TAG,"cacheNextPageData() startIndex="+startIndex+", endIndex="+endIndex);
List nextList = UIData.getListRows(startIndex,endIndex);
lazyData.getListData().addAll(nextList);
SystemClock.sleep(3000);//休息3秒,模拟网络延迟
}
@Override
public void updateItemView(View convertView, Object bean) {//更新每一行
updateItem(convertView, (Row) bean);
}
}
));
}
}).execute(new String[]{});
}