热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

下拉刷新快速使用

下拉刷新下载地址http:github.comchrisbanesAndroid-pullToRefresh下拉刷新下载的源码新建项目引用1.Pull

             下拉刷新

 

下载地址http://github.com/chrisbanes/Android-pullToRefresh

//下拉刷新下载的源码

 


//新建项目引用

 


 

1.PullToRefreshListFragment------>添加------library

(对着项目右键----->Properties----->android)

 

 

 

 

 

2.PullToRefreshViewPager------也添加------library



 

 

3.LauncherActivity---------------添加3个库

 

 

//新建项目-----UsingListView------也添加3个库

 

 

复制libs包写的android-support-v4.jar包分别拷入 其他的4个库包中(覆盖到原来的)

 




 

//activity_main.xml

    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_
    android:layout_
    android:orientation="vertical"
    tools:cOntext=".MainActivity" >

  

    android:id="@+id/mylv"
    android:layout_
    android:layout_
    >
    
      
    

    
    
    





 


//MainActivity---主程序

package com.jikexueyuan.usinglistview;

import java.util.ArrayList;
import java.util.List;


import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;


import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView;


public class MainActivity extends Activity {
private PullToRefreshListView lv;
private ArrayAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

lv=(PullToRefreshListView) findViewById(R.id.mylv);

List arr=new ArrayList();
arr.add("jikexueyuan");
arr.add("eoe");

adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,arr);
lv.setAdapter(adapter);

lv.setOnRefreshListener(new OnRefreshListener() {


@Override
public void onRefresh(PullToRefreshBase refreshView) {


//new AsyncTask()-->Void(V要大写)
  new AsyncTask() {


protected Void doInBackground(Void... params) {

try {

Thread.sleep(3000);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
      //在这里执行主线程的操作
 
@SuppressLint("NewApi")
protected void onPostExecute(Void result) {
  //添加数据
  adapter.addAll("Hello","大家好");
  //通知listview,下载数据
  lv.onRefreshComplete();
  
  };
  }.execute();//执行

}


});
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}


}





 

 


推荐阅读
author-avatar
bcz8936810
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有