PullToRefreshBase上拉下

package com.bawei.day13.frag;

import android.os.AsyncTask;
import android.os.Handler;
import android.view.View;
import android.widget.ListView;

import com.bawei.day13.R;
import com.bawei.day13.base.BaseFragment;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class Fragment1 extends BaseFragment {
private int page = 1;
private Handler handler = new Handler();

private PullToRefreshListView pul;

@Override
protected int layoutResID() {
    return R.layout.fragment1;
}

@Override
protected void initView(View view) {
    pul = view.findViewById(R.id.pul);


}


@Override
protected void initData() {
    //设置pulllidtview
    pul.setMode(PullToRefreshBase.Mode.BOTH);
    //设置刷新事件
    pul.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2() {
        @Override
        public void onPullDownToRefresh(PullToRefreshBase refreshView) {
            page =1;
            getNetData();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    pul.onRefreshComplete();
                }
            },2000);
        }

        @Override
        public void onPullUpToRefresh(PullToRefreshBase refreshView) {

            page++;
            getNetData();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    pul.onRefreshComplete();
                }
            },2000);
        }
    });
    getNetData();

}

private void getNetData() {
}

private class MyAsyncTask extends AsyncTask{

你可能感兴趣的:(学习资料)