Pull刷新加载

package com.example.huangj5;

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

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.handmark.pulltorefresh.library.PullToRefreshGridView;
import com.lidroid.xutils.BitmapUtils;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity {

    private PullToRefreshGridView pull_refresh_grid;
    int qwe = 10;
    private List<String> asd;
    private MyAdapter m;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Data();
        pull_refresh_grid = (PullToRefreshGridView)findViewById(R.id.pull_refresh_grid);
        m = new MyAdapter();
        pull_refresh_grid.setAdapter(m);
        pull_refresh_grid.setOnRefreshListener(new OnRefreshListener2<GridView>() {


            @Override
            public void onPullDownToRefresh(
                    PullToRefreshBase<GridView> refreshView) {
            qwe = qwe+5;
            Data();
            m = new MyAdapter();
            pull_refresh_grid.setAdapter(m);
            m.notifyDataSetChanged();
            pull_refresh_grid.onRefreshComplete();
            
            }
            @Override
            public void onPullUpToRefresh(
                    PullToRefreshBase<GridView> refreshView) {
                qwe = qwe+1;
                Data();
                m = new MyAdapter();
                pull_refresh_grid.setAdapter(m);
                m.notifyDataSetChanged();
                pull_refresh_grid.onRefreshComplete();    
            }

        });
        
    }
    class MyAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return asd.size();
        }

        @Override
        public Object getItem(int arg0) {
            return null;
        }

        @Override
        public long getItemId(int arg0) {
            return 0;
        }

        @Override
        public View getView(int arg0, View arg1, ViewGroup arg2) {
            arg1 = View.inflate(MainActivity.this,R.layout.item,null);
            TextView text_title = (TextView)arg1.findViewById(R.id.text_title);
            text_title.setText(asd.get(arg0));
            return arg1;
        }
        
    }
    private void Data() {
        asd = new ArrayList<String>();
        for (int i = 0; i < qwe; i++) {
        asd.add("q"+i);
        }
    }

}

原文地址:https://www.cnblogs.com/3674-it/p/5551080.html