zoukankan      html  css  js  c++  java
  • 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(); } }

  • 相关阅读:
    童年记忆
    展现、通讯、IO
    通电自动开机
    英雄每多屠狗辈,自古侠女出风尘(看黄金大劫案有感)
    反射整理学习<一>(转)
    在ASP.NET中跟踪和恢复大文件下载
    高内聚、低耦合
    你需要权限才能执行此操作
    WP7应用开发笔记(5) 通信设计
    一个简单的软件工程流程
  • 原文地址:https://www.cnblogs.com/1995yu/p/5424257.html
Copyright © 2011-2022 走看看