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

  • 相关阅读:
    iphone实时通话开源框架pjsip编译-pjsua运行测试
    iOS开发之使用pjsip开发VoIP应用程序
    Windows7下JDK+Tomcat的安装与配置
    ios xmpp开发应用后台模式接收聊天信息[转]
    IOS基础控件总结
    Objective C Foundation基础框架[转]
    Garbage Collection 垃圾收集
    Java 内存溢出分析
    Centos下MySQL使用总结
    不同项目数据交互
  • 原文地址:https://www.cnblogs.com/1995yu/p/5424257.html
Copyright © 2020-2023  润新知