Android中的延迟加载系列(ListView 2)
来源:互联网 发布:大众cc轮毂数据 编辑:程序博客网 时间:2024/06/05 08:59
上一节讲述了Listview延迟加载的封装,本节将讲述如何在Activity中进行调用。
首先定义一个ListView布局
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/linearLayoutWhole"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- android:orientation="vertical">
- <ListView android:id="@android:id/list" android:layout_width="fill_parent"
- android:layout_height="fill_parent" android:drawSelectorOnTop="false" />
- </LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/linearLayoutWhole"android:layout_width="fill_parent" android:layout_height="fill_parent"android:orientation="vertical"><ListView android:id="@android:id/list" android:layout_width="fill_parent"android:layout_height="fill_parent" android:drawSelectorOnTop="false" /></LinearLayout>
其次定义一个ListActivity,引入上述布局
- public class LazyLoadingActivity extends ListActivity
public class LazyLoadingActivity extends ListActivity
在onCreate() 方法中加载数据和布局,LongOperation更多的相信信息请参照 页面(Activity)之间的平滑跳转及封 法中加载数据
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- new LongOperation(this,new Excution(){
- @Override
- public void longExcute(){
- lazyData = new LazyListData<Row>(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<Row>(
- 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<Row> 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[]{});
- }
@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);new LongOperation(this,new Excution(){@Overridepublic void longExcute(){lazyData = new LazyListData<Row>(UIData.getTotalRows(),UIData.getListRows(0,LazyAdapter.PAGE_SIZE_LAZY-1));SystemClock.sleep(3000);//休息3秒,模拟网络延迟}@Overridepublic void uiUpdate(){setContentView(R.layout.empty_list); setListAdapter(new LazyAdapter<Row>(LazyLoadingActivity.this,R.layout.row,//list中的行布局lazyData.getListData(),//得到数据lazyData.getTotalRows(),//得到总行数new LazyLoading(){@Overridepublic void cacheNextPageData(int startIndex, int endIndex) {//加载下一页Log.d(TAG,"cacheNextPageData() startIndex="+startIndex+", endIndex="+endIndex);List<Row> nextList = UIData.getListRows(startIndex,endIndex);lazyData.getListData().addAll(nextList); SystemClock.sleep(3000);//休息3秒,模拟网络延迟}@Overridepublic void updateItemView(View convertView, Object bean) {//更新每一行updateItem(convertView, (Row) bean);}}));}}).execute(new String[]{});}
new LazyAdapter()方法是封装之后的延迟加载适配,参见程序代码说明。
下一节将通过一个完整项目进行展示。(待续)
- Android中的延迟加载系列(ListView 2)
- Android中的延迟加载系列(ListView 2)
- Android中的延迟加载系列(ListView 1)
- Android中的延迟加载系列(ListView 1)
- Android中的延迟加载系列(ListView 3 含完整代码及工程下载)
- Android中的延迟加载系列(ListView 3 含完整代码及工程下载)
- Android中的延迟加载系列4(ImageView)
- Android中的延迟加载系列4(ImageView)
- Android中的延迟加载系列5 (综合案例 含完整代码及工程下载)
- Android中的延迟加载系列5 (综合案例 含完整代码及工程下载)
- android图片延迟加载,照片墙,listview中图片的延迟加载(国外制造)
- ListView异步延迟加载
- android viewpager中的fragment 延迟加载数据
- Android 延迟加载( AsynTask 异步加载)
- ibatis中的延迟加载(失效)
- Hibernate中的延迟加载
- Hibernate中的延迟加载
- js中的延迟加载
- [Python]小练习 -- 模拟登陆人人网
- POJ 1456 Supermarket
- 玩转SSRS第一篇---报表服务的配置
- android开发过程中涉及到的“概念”摘要
- 文件权限与目录
- Android中的延迟加载系列(ListView 2)
- UVa 784 Maze Exploration(DFS)
- 黑马程序员——银行业务调度系统
- Hadoop的昨天与今天
- 手把手叫你玩转网络编程
- Android中的延迟加载系列(ListView 3 含完整代码及工程下载)
- CentOS 6.2/6.3 Xmanager 配置
- 由浅入深探究mysql索引结构原理、性能分析与优化
- Constructors in C++11