package com.example.pulltodemo;
import java.util.ArrayList;
import java.util.List;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.DateUtils;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends Activity {
Handler mHandler = new Handler();
List
listbb = new ArrayList
();
private com.handmark.pulltorefresh.library.PullToRefreshListView show_list;
int a = 1;
private List
listaa;
private MyListAdapter myListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
listaa = new ArrayList
();
for (int i = 0; i < 20; i++) {
listaa.add("aaa----------");
}
myListAdapter = new MyListAdapter(this, listaa);
show_list.setAdapter(myListAdapter);
show_list.setOnRefreshListener(new OnRefreshListener2
() { /** * 下拉刷新 */ @Override public void onPullDownToRefresh(PullToRefreshBase refreshView) { // TODO Auto-generated method stub String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); // 显示最后更新的时间 refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label); mHandler.postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub show_list.onRefreshComplete(); } }, 5000); } /** * 上拉加载 */ @Override public void onPullUpToRefresh(PullToRefreshBase refreshView) { // TODO Auto-generated method stub String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); // 显示最后更新的时间 refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label); mHandler.postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub if (a == 0) { show_list.onRefreshComplete(); Toast.makeText(MainActivity.this, "没有更多数据了", 0).show(); } else { for (int i = 0; i < 20; i++) { listaa.add("bbb------"); } a = 0; listbb.addAll(listaa); myListAdapter.setListaa(listbb); myListAdapter.notifyDataSetChanged(); show_list.onRefreshComplete(); } } }, 2000); } }); } private void initView() { // TODO Auto-generated method stub show_list = (com.handmark.pulltorefresh.library.PullToRefreshListView) findViewById(R.id.show_list); } }
PullToRefresh
最新推荐文章于 2019-05-15 11:26:20 发布