pull刷新
package com.example.mylist; import java.util.ArrayList; import java.util.List; import com.example.adapter.MyAdapter; import com.example.adapter.MyAdapter1; import com.example.myutils.MyUtils; import com.example.vo.Data; import com.example.vo.News; import com.google.gson.Gson; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener; import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener; import com.handmark.pulltorefresh.library.PullToRefreshListView; import android.os.Bundle; import android.os.Handler; import android.text.format.DateUtils; import android.widget.ListView; import android.app.Activity; public class MainActivity extends Activity implements OnRefreshListener, OnLastItemVisibleListener { private PullToRefreshListView lv; int p=1; private MyAdapter1 adapter; List list_push=new ArrayList(); Handler handler=new Handler(){ public void handleMessage(android.os.Message msg) { if(msg.what==1){ List data = (List) msg.obj; System.out.println(data+"============="); list_push=data; adapter = new MyAdapter1(MainActivity.this, list_push); lv.setAdapter(adapter); } if(msg.what==2){ List data2 = (List) msg.obj; list_push.addAll(data2); adapter.notifyDataSetChanged(); } }; }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); getdata(); } private void init() { lv = (PullToRefreshListView) findViewById(R.id.lv); lv.setOnRefreshListener(this); lv.setOnLastItemVisibleListener(this); } private void getdata() { // TODO Auto-generated method stub new Thread(){ public void run() { String str=MyUtils.Check_j(p); Gson g=new Gson(); News news=g.fromJson(str, News.class); List list=news.getData(); handler.sendMessage(handler.obtainMessage(1, list)); }; }.start(); } @Override public void onRefresh(PullToRefreshBase refreshView) { String twoInfo = DateUtils.formatDateTime(getApplicationContext(),System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); getdata(); adapter.notifyDataSetChanged(); } @Override public void onLastItemVisible() { new Thread(){ public void run() { String str=MyUtils.Check_j(p++); Gson g=new Gson(); News news=g.fromJson(str, News.class); List list=news.getData(); handler.sendMessage(handler.obtainMessage(2, list)); }; }.start(); } }
最新文章
- win10下安装mysql5.7.16(解压缩版)
- HDFS操作
- UIPickerView简单应用
- c#中DropDownList控件绑定枚举数据
- MySQL(3):数据库操作
- C++ STL 算法精选之查找篇
- 【HeadFirst 设计模式总结】2 观察者模式
- express respond.send 和 end的区别
- 搭建自己的Webpack项目
- 在lnmp1.3布置的web服务器上运行thinkphp3.2.3项目pathinfo路径模式
- [转]2016年linux运维人员必会开源运维工具体系
- Qt5 How to translate App UI languages
- Unity 游戏开发技巧集锦之使用cookie类型的纹理模拟云层的移动
- 使用matplotlib绘图(一)之折线图
- 基于Xcode5的本地化
- ubuntu安装ICE记录
- 手动爬虫之流程笔记1(python3)
- Spring中为什么实体类不用注入
- Host 'XXX' is not allowed to connect to this MySQL server解决方案
- 配置Nginx与tomcat负责均衡集群,
热门文章
- 【转】PowerShell入门(一):PowerShell能干什么?
- Oracle数据库DOC命令导入导出(2014-3-10记)
- angularJS ng-grid 配置
- python之redis
- 学DIV+CSS技术,如何入门?(2)
- 数据库连接池配置 - Oracle,SQL Server,DB2,MYSQL,SQLLITE3
- Python学习笔记(2)
- Openstack+Kubernetes+Docker微服务实践之路--选型
- bzoj 4415: [Shoi2013]发牌
- js获取url中的参数值