frist:
import API from github
library , PullToRefreshListFragment , PullToRefreshViewPager
second:
create my android project(MyListView)
create xml file , call main.xml
in xml file , create PullToRefreshListView
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/mylv"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</com.handmark.pulltorefresh.library.PullToRefreshListView>
third:
in MainActivity , create two variable
private PullToRefreshListView lv;
private ArrayAdapter<String> adapter;
in onCreate() method , get object from main.xml
lv=(PullToRefreshListView) findViewById(R.id.mylv);
List<String> arr=new ArrayList<String>();
you can add some params to "arr" , like it
arr.add("huaruan");
add new ArrayAdapter<String> object to lv
lv.setAdapter(adapter);
then setOnRefreshListener for lv and write overrid method
lv.setOnRefreshListener(new OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
// TODO Auto-generated method stub
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result)
{
int i=(int) (Math.random()*3);
String jString=Integer.toString(i);
adapter.addAll("hello",jString);
lv.onRefreshComplete();
};
}.execute();
}
});
to here , this android PullToRefresh project is ok , you can run it to see effect