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(); } }

  • 相关阅读:
    JavaScriptFunction对象(函数)的声明和作用域
    JavaScript常用对象的属性及方法(2)
    html+css>backgroundimg(背景图的设置)
    JavaScript知识点>运算规则与运算(逻辑、位)
    JavaScript知识点:分支结构(if、switch)+算法例题
    JavaScript常用对象的属性及方法(1)
    一些学习js的算法题目
    隐马尔科夫模型
    Eclipse插件开发小结
    二叉树排序和堆排序
  • 原文地址:https://www.cnblogs.com/1995yu/p/5424257.html
Copyright © 2011-2022 走看看