PullToRefresh
2016-03-19 17:18
330 查看
<strong>package com.bwie.refresh; import java.lang.reflect.Array; import java.util.Arrays; import java.util.LinkedList; import com.handmark.pulltorefresh.library.ILoadingLayout; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshListView; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.text.format.DateUtils; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends Activity { private PullToRefreshListView pull_list; private ArrayAdapter<String> mAdapter; private LinkedList<String> linkedList; private ListView refreshableView; private ListView listView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //找控件 initview(); } private void initview() { //找控件 pull_list=(PullToRefreshListView)findViewById(R.id.pull_list); ILoadingLayout startLabels = pull_list .getLoadingLayoutProxy(true, false); startLabels.setPullLabel("下拉刷新...");// 刚下拉时,显示的提示 startLabels.setRefreshingLabel("正在载入...");// 刷新时 startLabels.setReleaseLabel("放开刷新...");// 下来达到一定距离时,显示的提示 ILoadingLayout endLabels = pull_list.getLoadingLayoutProxy( false, true); endLabels.setPullLabel("上拉刷新...");// 刚下拉时,显示的提示 endLabels.setRefreshingLabel("正在载入...");// 刷新时 endLabels.setReleaseLabel("放开刷新...");// 下来达到一定距离时,显示的提示 pull_list.setOnRefreshListener(new OnRefreshListener<ListView>() { @Override public void onRefresh(PullToRefreshBase<ListView> refreshView) { String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);//3.刷新界面处理代理,显示新的时间 new GetDataTask().execute(); } }); pull_list.setOnLastItemVisibleListener(new OnLastItemVisibleListener() { @Override public void onLastItemVisible() { } }); refreshableView = pull_list.getRefreshableView(); pull_list.setMode(Mode.BOTH); //构建数据 linkedList = new LinkedList<String>(); linkedList.addAll(Arrays.asList(mStrings)); //建立适配器 mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, linkedList); //设置适配器 refreshableView.setAdapter(mAdapter); //为refreshableView添加上下文菜单 registerForContextMenu(refreshableView); } //异步加载 private class GetDataTask extends AsyncTask<Void, Void, String[]>{ @Override protected String[] doInBackground(Void... params) { try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } return mStrings; } @Override protected void onPostExecute(String[] result) { super.onPostExecute(result); //刷新加载数据 linkedList.addFirst("加载的数据"); //刷新适配器 mAdapter.notifyDataSetChanged(); //刷新完成 pull_list.onRefreshComplete(); } } public static final String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre", "Allgauer Emmentaler" }; } <com.handmark.pulltorefresh.library.PullToRefreshListView xmlns:ptr="http://schemas.android.com/apk/res-auto" android:id="@+id/pulltorefreshlistview" android:layout_width="match_parent" android:layout_height="match_parent" ptr:ptrDrawable="@drawable/default_ptr_flip" ptr:ptrAnimationStyle="flip" ptr:ptrHeaderBackground="#383838"/> </strong>
相关文章推荐
- Android基础
- source insight 相对路径
- Apache用户认证
- 十二、Bitmap的加载和Cache
- 第二周作业(2)
- (转)C# 温故而知新:Stream篇(六)
- Android官方开发文档Training系列课程中文版:构建第一款安卓应用之入门指南
- iOS TableView顶部上方留白的问题
- quickbuild 设置使用外部数据库
- Oracle学习笔记(2)——系统用户与表空间
- vs2013安装练习
- vs2010安装和使用
- NSThread
- NSThread
- 3D逃亡-简单搜素练习2
- 手把手教你制作easyUI+bootstrap工作站,主要学习tabs方法
- iOS TableView 滚动到最后一行
- java操作properties配置文件
- C语言中可变形参列表
- java操作properties配置文件