上下拉刷新 轮播图 listview

Posted sdfkjg

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了上下拉刷新 轮播图 listview相关的知识,希望对你有一定的参考价值。

activity_main

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="zhanghaijiao.bawei.com.day10_demo3.MainActivity">

    <!--只能有一个子孩子 -->
    <com.handmark.pulltorefresh.library.PullToRefreshScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/psv">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            <!--轮播图-->
            <android.support.v4.view.ViewPager
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:id="@+id/vp"></android.support.v4.view.ViewPager>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/lin_point"
                    android:orientation="horizontal"
                    android:gravity="center"
                    android:layout_gravity="bottom"></LinearLayout>

            </FrameLayout>


            <!--listview-->
            <!--<ListView-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="match_parent"-->
                <!--android:id="@+id/lv"></ListView>-->
            <zhanghaijiao.bawei.com.day10_demo3.MyListView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/lv"></zhanghaijiao.bawei.com.day10_demo3.MyListView>

        </LinearLayout>

    </com.handmark.pulltorefresh.library.PullToRefreshScrollView>



</LinearLayout>

main_activity

package zhanghaijiao.bawei.com.day10_demo3;

import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;

import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private PullToRefreshScrollView psv;

    private int pageIndex=1;
    private int operType=1;//1:刷新 2:加载更多

    private String myurl="http://365jia.cn/news/api3/365jia/news/headline?page="+pageIndex;

    private  List<ResultData.DataBeanX.DataBean> datas=new ArrayList<>();
    private ListViewAdapter adapter;
    private ListView listView;
    private ViewPager viewPager;
    private List<String> imgUrls=new ArrayList<>();
    private LinearLayout linPoint;

    private List<ImageView> lists=new ArrayList<>();
    private Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            int cIndex=viewPager.getCurrentItem();
            cIndex++;
            viewPager.setCurrentItem(cIndex);

            //改变指示器
            setSelectedPoint(cIndex%lists.size());


            sendEmptyMessageDelayed(0,1000);

        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        psv = findViewById(R.id.psv);
        listView = findViewById(R.id.lv);
        viewPager = findViewById(R.id.vp);
        linPoint = findViewById(R.id.lin_point);




        //初使化 pullToRefreshScrollView
        initPsv();


        //请求网络数据
        requestNetData();





    }

    private void requestNetData() {
        new MyTask().execute(myurl);

    }
    class MyTask extends AsyncTask<String,Void,String> {

        @Override
        protected String doInBackground(String... strings) {
            try {
                URL url=new URL(strings[0]);
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

                urlConnection.setRequestMethod("GET");
                urlConnection.setReadTimeout(5000);
                urlConnection.setConnectTimeout(5000);

                if(urlConnection.getResponseCode()==200){
                    InputStream inputStream = urlConnection.getInputStream();

                    String s = streamToString(inputStream);
                    return s;



                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);

            Gson gson=new Gson();
            ResultData resultData = gson.fromJson(s, ResultData.class);
            //新请求下来的数据
            List<ResultData.DataBeanX.DataBean> data = resultData.getData().getData();

            //展示轮播图
            showPics(data);


            if(operType==1){
                datas.clear();//清空
            }
            datas.addAll(data);

            setAdapter();

            //关闭头尾布局
            psv.onRefreshComplete();





        }
    }

    private void showPics(List<ResultData.DataBeanX.DataBean> data) {
        imgUrls.clear();
        //为轮播图添加地址
        imgUrls.add("http://365jia.cn/uploads/"+data.get(0).getPics().get(0));
        imgUrls.add("http://365jia.cn/uploads/"+data.get(1).getPics().get(0));
        imgUrls.add("http://365jia.cn/uploads/"+data.get(2).getPics().get(0));

        MyVpAdapter adapter=new MyVpAdapter(imgUrls,MainActivity.this);
        viewPager.setAdapter(adapter);

        //初使化指示器
        initPoint();


        //发送消息,实现自动轮播
        mHandler.sendEmptyMessageDelayed(0,1000);
    }

    //设置选中的小圆点
    private  void setSelectedPoint(int pageIndex){
        for (int i = 0; i <lists.size() ; i++) {
            if(i==pageIndex){
                lists.get(i).setImageResource(R.drawable.point_selected);
            }else {
                lists.get(i).setImageResource(R.drawable.point_unselected);
            }

        }

    }

    private void initPoint() {
        for (int i = 0; i <imgUrls.size() ; i++) {
            ImageView imageView=new ImageView(this);
            //设置它的布局参数
            LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
            params.setMargins(0,0,10,0);//设置右边的间隔
            if(i==0){
                imageView.setImageResource(R.drawable.point_selected);//选中的小圆点
            }else{
                imageView.setImageResource(R.drawable.point_unselected);
            }
            linPoint.addView(imageView,params);

            lists.add(imageView);
        }

    }

    public void setAdapter(){
        if (adapter == null) {
            adapter = new ListViewAdapter(datas,MainActivity.this);
            listView.setAdapter(adapter);
        }else {
            adapter.notifyDataSetChanged();
        }

    }

    /**
     * 将流转换成String
     * @param stream
     */
    private String streamToString(InputStream stream) {
        StringBuilder sbuilder=new StringBuilder();
        String str;
        BufferedReader reader=new BufferedReader(new InputStreamReader(stream));

        try {
            while ((str=reader.readLine())!=null){
                sbuilder.append(str);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  sbuilder.toString();

    }

    private void initPsv() {
        //1.设置模式
        psv.setMode(PullToRefreshBase.Mode.BOTH);
        //2.设置监听
        psv.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> pullToRefreshBase) {
                //刷新回调
                operType=1;
                pageIndex=1;
                myurl="http://365jia.cn/news/api3/365jia/news/headline?page="+pageIndex;
                requestNetData();

            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> pullToRefreshBase) {
                //加载回调
                operType=2;
                pageIndex++;
                myurl="http://365jia.cn/news/api3/365jia/news/headline?page="+pageIndex;
                requestNetData();

            }
        });
    }
}

ResultData

 /**
     * httpStatusCode : 200
     * code : 0
     * data : {"page":1,"perpage":20,"max_page":130,"total":2591,"data":[{"id":3524385,"title":"合肥城市总体规划编制大调研工作启动 今年12月完成总规纲要初步成果","link":"lsapp://cn.ahurls.news/news?id=3524385","pics":["appletrecommend/201804/5ade91c99a715.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":394,"comment_amount_label":"0","views_label":"394"},{"id":3524236,"title":"快了!合肥\u201c租售同权\u201d配套入学政策最迟5月底制定","link":"lsapp://cn.ahurls.news/news?id=3524236","pics":["appletrecommend/201804/5ade6af7f0bdf.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":5,"source":"","type_sign":"","inner_news":1,"views":1073,"comment_amount_label":"5","views_label":"1073"},{"id":3524304,"title":"合肥城隍庙综合改造基本结束 小商品世界\u201c五一\u201d回归","link":"lsapp://cn.ahurls.news/news?id=3524304","pics":["appletrecommend/201804/5ade8dd32c6af.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":596,"comment_amount_label":"0","views_label":"596"},{"id":3524230,"title":"共享轮椅现身合肥扫码即可推走 前2小时免费之后2元/小时","link":"lsapp://cn.ahurls.news/news?id=3524230","pics":["appletrecommend/201804/5ade65ada6d9a.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":3,"source":"","type_sign":"","inner_news":1,"views":1037,"comment_amount_label":"3","views_label":"1037"},{"id":3524084,"title":"《钱途》第111期:合肥小三劝退师 服务高端家庭从业十余年\u201c接单\u201d1000多件","link":"lsapp://cn.ahurls.news/image_news?id=3524084","pics":["special/tuku/201804/5add9971130ea73397.jpg","special/tuku/201804/5add997053c4743125.jpg","special/tuku/201804/5add9970c876320792.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":1810,"comment_amount_label":"2","views_label":"1810","pics_new":["special/tuku/201804/5add9971130ea73397.jpg"]},{"id":3524190,"title":"调查:合肥整治餐饮油烟关停1500余家店,你家楼下还有吗?","link":"lsapp://cn.ahurls.news/news?id=3524190","pics":["appletrecommend/201804/5adbc9336ad61.jpg"],"t":"url","type":"vote","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":4,"source":"","type_sign":"投票","inner_news":1,"views":694,"comment_amount_label":"4","views_label":"694","pics_new":["appletrecommend/201804/5adbc9336ad61.jpg"]},{"id":3524271,"title":"合肥全力推进\u201c厕所革命\u201d 4A级以上景区需配\u201c第三卫生间\u201d","link":"lsapp://cn.ahurls.news/news?id=3524271","pics":["appletrecommend/201804/5ade8ec4de18c.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":470,"comment_amount_label":"0","views_label":"470"},{"id":3524232,"title":"合肥市中心图书馆设计方案出炉 设有下沉广场和多层观景平台","link":"lsapp://cn.ahurls.news/news?id=3524232","pics":["appletrecommend/201804/5ade655ad5710.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":1225,"comment_amount_label":"2","views_label":"1225"},{"id":3523945,"title":"《门生》:合肥00后成安徽史上首位中传播音艺考全国第一考生 已揽获5所高校艺考合格证","link":"lsapp://cn.ahurls.news/image_news?id=3523945","pics":["special/tuku/201804/5add914c99d7d67189.jpg","special/tuku/201804/5add5910a971d45459.jpg","special/tuku/201804/5add5936f40f773472.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":3118,"comment_amount_label":"2","views_label":"3118","pics_new":["special/tuku/201804/5add914c99d7d67189.jpg"]},{"id":3524506,"title":"合肥地铁3号线阜淮区间双线贯通 已有30条单线隧道贯通","link":"lsapp://cn.ahurls.news/news?id=3524506","pics":["appletrecommend/201804/5adea08287125.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":138,"comment_amount_label":"0","views_label":"138"},{"id":3524498,"title":"安徽今起雨过天晴气温将逐步回升 29日前后还有降水过程","link":"lsapp://cn.ahurls.news/news?id=3524498","pics":["appletrecommend/201804/5adea01bb50af.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":154,"comment_amount_label":"0","views_label":"154"},{"id":3524231,"title":"合肥一小区物业尝试推行刷卡乘电梯 辖区社居委要求暂停","link":"lsapp://cn.ahurls.news/news?id=3524231","pics":["appletrecommend/201804/5ade66ce49ec3.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":3,"source":"","type_sign":"","inner_news":1,"views":1248,"comment_amount_label":"3","views_label":"1248"},{"id":3523430,"title":"【专题】桂林龙舟侧翻17人亡 遇难人员家属:我眼睁睁看着儿子在水中挣扎","link":"lsapp://cn.ahurls.news/special?id=3523430","pics":["18/0422/5adbf3bcbec54.jpg"],"t":"url","type":"special","alias":"headline","pic_amount":0,"style":"single_fill","comment_amount":2,"source":"","type_sign":"专题","inner_news":1,"views":4075,"comment_amount_label":"2","views_label":"4075","pics_new":["18/0422/5adbf3bcbec54.jpg"]},{"id":3524380,"title":"水壶里发现避孕套 在烧水壶里尿尿 还有大妈竟用酒店热水壶做这种事...","link":"lsapp://cn.ahurls.news/news?id=3524380","pics":["appletrecommend/201804/5ade8fb8ec477.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":442,"comment_amount_label":"2","views_label":"442"},{"id":3524340,"title":"合肥城区示范性菜市场有奖征集 提档升级\u201c金点子\u201d及标识(Logo)等你来定","link":"lsapp://cn.ahurls.news/news?id=3524340","pics":["appletrecommend/201804/5ade8a4720eff.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":316,"comment_amount_label":"0","views_label":"316"},{"id":3524246,"title":"18岁女孩称被合租女生带回的男生砍毁容 左脸缝200多针","link":"lsapp://cn.ahurls.news/image_news?id=3524246","pics":["special/tuku/201804/5ade6e4db78b193298.jpg","special/tuku/201804/5ade6e4da76c711305.jpg","special/tuku/201804/5ade6e4d84c1e32717.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":1,"source":"","type_sign":"","inner_news":1,"views":1965,"comment_amount_label":"1","views_label":"1965","pics_new":["special/tuku/201804/5ade6e4db78b193298.jpg","special/tuku/201804/5ade6e4da76c711305.jpg","special/tuku/201804/5ade6e4d84c1e32717.jpg"]},{"id":3524118,"title":"上周合肥4盘开盘推500余套房源 网传经开某盘将加推超4000组客户预约","link":"lsapp://cn.ahurls.news/news?id=3524118","pics":["appletrecommend/201804/5ade6414ef95f.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":1,"source":"","type_sign":"","inner_news":1,"views":867,"comment_amount_label":"1","views_label":"867"},{"id":3524224,"title":"合肥7家A级景区获评\u201c平安景区\u201d 包公园已连续两年获此殊荣","link":"lsapp://cn.ahurls.news/news?id=3524224","pics":["appletrecommend/201804/5ade639f47cd9.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":1,"source":"","type_sign":"","inner_news":1,"views":718,"comment_amount_label":"1","views_label":"718"},{"id":3522438,"title":"【专题】五一还去挤黄山?这才是合肥人假期最值得去的9个地方!","link":"lsapp://cn.ahurls.news/special?id=3522438","pics":["18/0419/5ad85e298287a.jpg"],"t":"url","type":"special","alias":"headline","pic_amount":0,"style":"single_fill","comment_amount":2,"source":"","type_sign":"专题","inner_news":1,"views":3875,"comment_amount_label":"2","views_label":"3875","pics_new":["18/0419/5ad85e298287a.jpg"]},{"id":3524350,"title":"安徽将建立教师个人信用制度 建立师德考核\u201c负面清单\u201d","link":"lsapp://cn.ahurls.news/news?id=3524350","pics":["appletrecommend/201804/5ade989c2758d.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":353,"comment_amount_label":"0","views_label":"353"},{"id":3524068,"title":"合肥兵哥哥们的爱情故事 泪目!异地军恋那些事儿","link":"lsapp://cn.ahurls.news/news?id=3524068","pics":["appletrecommend/201804/5ade64496d7a0.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":1022,"comment_amount_label":"2","views_label":"1022"},{"id":3524391,"title":"25岁小伙如何月\u201c赚\u201d100万?肥西一男子信了!","link":"lsapp://cn.ahurls.news/image_news?id=3524391","pics":["special/tuku/201804/5ade8d81a6b8f80659.jpg","special/tuku/201804/5ade8d81be67582864.jpg","special/tuku/201804/5ade8d81e18cf26738.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":1507,"comment_amount_label":"0","views_label":"1507","pics_new":["special/tuku/201804/5ade8d81a6b8f80659.jpg"]},{"id":3524237,"title":"合肥2家开发商因拒绝公积金贷款 被要求限期改正","link":"lsapp://cn.ahurls.news/news?id=3524237","pics":["appletrecommend/201804/5ade69aad18a1.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":1,"source":"","type_sign":"","inner_news":1,"views":931,"comment_amount_label":"1","views_label":"931"},{"id":3524295,"title":"突发!广东KTV火灾致18死5伤 初步调查系人为纵火","link":"lsapp://cn.ahurls.news/news?id=3524295","pics":["appletrecommend/201804/5ade929e082b2.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":1,"source":"","type_sign":"","inner_news":1,"views":1039,"comment_amount_label":"1","views_label":"1039"},{"id":3524234,"title":"过期药毒性惊人!误服威胁生命 竟有人3折回收后卖到农村、小诊所","link":"lsapp://cn.ahurls.news/news?id=3524234","pics":["appletrecommend/201804/5ade673140628.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":1763,"comment_amount_label":"2","views_label":"1763"},{"id":3524433,"title":"小乌龟\u201c成精了\u201d?色彩丰富还有卡通造型 8块1只!","link":"lsapp://cn.ahurls.news/image_news?id=3524433","pics":["special/tuku/201804/5ade9163920d570240.jpg","special/tuku/201804/5ade9163d04bd20937.jpg","special/tuku/201804/5ade9163eb66044417.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":858,"comment_amount_label":"0","views_label":"858","pics_new":["special/tuku/201804/5ade9163920d570240.jpg"]},{"id":3524516,"title":"河南36名高中生未按时就寝遭劝退 教体局回应:校方处理过激","link":"lsapp://cn.ahurls.news/news?id=3524516","pics":["appletrecommend/201804/5adea41b4d356.png"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":84,"comment_amount_label":"0","views_label":"84"},{"id":3524509,"title":"少女洗澡煤气爆炸全身90%特重烧伤 17岁高二女孩忍痛报警","link":"lsapp://cn.ahurls.news/news?id=3524509","pics":["appletrecommend/201804/5adea3cf0523e.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":2306,"comment_amount_label":"0","views_label":"2306"},{"id":3524394,"title":"合肥:擅自设置入河排污口将被追责 县级以上政府需两月一检","link":"lsapp://cn.ahurls.news/news?id=3524394","pics":["appletrecommend/201804/5adea386e023f.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":251,"comment_amount_label":"0","views_label":"251"},{"id":3524523,"title":"泰国男子直播打女友 因欠债压力大 怀疑被劈腿","link":"lsapp://cn.ahurls.news/image_news?id=3524523","pics":["special/tuku/201804/5adea1f93bd8f63280.jpg","special/tuku/201804/5adea1f8af17149308.jpg","special/tuku/201804/5adea1f8c609f10899.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":1507,"comment_amount_label":"0","views_label":"1507","pics_new":["special/tuku/201804/5adea1f93bd8f63280.jpg"]}],"extras":{"slider":[{"id":3524270,"pic":"18/0424/5ade8cee6a463.jpg","link":"lsapp://cn.ahurls.news/news?id=3524270","t":"url","inner_news":1,"title":"5月合肥杂技、音乐剧轮番上演","type":"nomal","type_sign":""},{"id":3524248,"pic":"18/0424/5ade70d2452d1.jpg","link":"lsapp://cn.ahurls.news/news?id=3524248","t":"url","inner_news":1,"title":"合肥水源故里小镇项目初步规划出炉","type":"nomal","type_sign":""},{"id":3524128,"pic":"18/0423/5addcfe577447.jpg","link":"lsapp://cn.ahurls.news/news?id=3524128","t":"url","inner_news":1,"title":"合肥2018义务教育招生方案5月出台","type":"nomal","type_sign":""},{"id":3523709,"pic":"18/0423/5add7461af5b5.jpg","link":"lsapp://cn.ahurls.news/news?id=3523709","t":"url","inner_news":1,"title":"安徽6批次不合格酒被下架召回","type":"nomal","type_sign":""},{"id":3516306,"pic":"18/0408/5ac9e1309834b.jpg","link":"lsapp://cn.ahurls.news/news?id=3516306","t":"url","inner_news":1,"title":"3月份勋章积分奖励名单出炉啦!","type":"nomal","type_sign":""}]},"bindtips":""}
     */

    private int httpStatusCode;
    private int code;
    private DataBeanX data;

    public int getHttpStatusCode() {
        return httpStatusCode;
    }

    public void setHttpStatusCode(int httpStatusCode) {
        this.httpStatusCode = httpStatusCode;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public DataBeanX getData() {
        return data;
    }

    public void setData(DataBeanX data) {
        this.data = data;
    }

    public static class DataBeanX {
        /**
         * page : 1
         * perpage : 20
         * max_page : 130
         * total : 2591
         * data : [{"id":3524385,"title":"合肥城市总体规划编制大调研工作启动 今年12月完成总规纲要初步成果","link":"lsapp://cn.ahurls.news/news?id=3524385","pics":["appletrecommend/201804/5ade91c99a715.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":394,"comment_amount_label":"0","views_label":"394"},{"id":3524236,"title":"快了!合肥\u201c租售同权\u201d配套入学政策最迟5月底制定","link":"lsapp://cn.ahurls.news/news?id=3524236","pics":["appletrecommend/201804/5ade6af7f0bdf.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":5,"source":"","type_sign":"","inner_news":1,"views":1073,"comment_amount_label":"5","views_label":"1073"},{"id":3524304,"title":"合肥城隍庙综合改造基本结束 小商品世界\u201c五一\u201d回归","link":"lsapp://cn.ahurls.news/news?id=3524304","pics":["appletrecommend/201804/5ade8dd32c6af.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":596,"comment_amount_label":"0","views_label":"596"},{"id":3524230,"title":"共享轮椅现身合肥扫码即可推走 前2小时免费之后2元/小时","link":"lsapp://cn.ahurls.news/news?id=3524230","pics":["appletrecommend/201804/5ade65ada6d9a.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":3,"source":"","type_sign":"","inner_news":1,"views":1037,"comment_amount_label":"3","views_label":"1037"},{"id":3524084,"title":"《钱途》第111期:合肥小三劝退师 服务高端家庭从业十余年\u201c接单\u201d1000多件","link":"lsapp://cn.ahurls.news/image_news?id=3524084","pics":["special/tuku/201804/5add9971130ea73397.jpg","special/tuku/201804/5add997053c4743125.jpg","special/tuku/201804/5add9970c876320792.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":1810,"comment_amount_label":"2","views_label":"1810","pics_new":["special/tuku/201804/5add9971130ea73397.jpg"]},{"id":3524190,"title":"调查:合肥整治餐饮油烟关停1500余家店,你家楼下还有吗?","link":"lsapp://cn.ahurls.news/news?id=3524190","pics":["appletrecommend/201804/5adbc9336ad61.jpg"],"t":"url","type":"vote","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":4,"source":"","type_sign":"投票","inner_news":1,"views":694,"comment_amount_label":"4","views_label":"694","pics_new":["appletrecommend/201804/5adbc9336ad61.jpg"]},{"id":3524271,"title":"合肥全力推进\u201c厕所革命\u201d 4A级以上景区需配\u201c第三卫生间\u201d","link":"lsapp://cn.ahurls.news/news?id=3524271","pics":["appletrecommend/201804/5ade8ec4de18c.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":470,"comment_amount_label":"0","views_label":"470"},{"id":3524232,"title":"合肥市中心图书馆设计方案出炉 设有下沉广场和多层观景平台","link":"lsapp://cn.ahurls.news/news?id=3524232","pics":["appletrecommend/201804/5ade655ad5710.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":1225,"comment_amount_label":"2","views_label":"1225"},{"id":3523945,"title":"《门生》:合肥00后成安徽史上首位中传播音艺考全国第一考生 已揽获5所高校艺考合格证","link":"lsapp://cn.ahurls.news/image_news?id=3523945","pics":["special/tuku/201804/5add914c99d7d67189.jpg","special/tuku/201804/5add5910a971d45459.jpg","special/tuku/201804/5add5936f40f773472.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":3118,"comment_amount_label":"2","views_label":"3118","pics_new":["special/tuku/201804/5add914c99d7d67189.jpg"]},{"id":3524506,"title":"合肥地铁3号线阜淮区间双线贯通 已有30条单线隧道贯通","link":"lsapp://cn.ahurls.news/news?id=3524506","pics":["appletrecommend/201804/5adea08287125.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":138,"comment_amount_label":"0","views_label":"138"},{"id":3524498,"title":"安徽今起雨过天晴气温将逐步回升 29日前后还有降水过程","link":"lsapp://cn.ahurls.news/news?id=3524498","pics":["appletrecommend/201804/5adea01bb50af.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":154,"comment_amount_label":"0","views_label":"154"},{"id":3524231,"title":"合肥一小区物业尝试推行刷卡乘电梯 辖区社居委要求暂停","link":"lsapp://cn.ahurls.news/news?id=3524231","pics":["appletrecommend/201804/5ade66ce49ec3.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":3,"source":"","type_sign":"","inner_news":1,"views":1248,"comment_amount_label":"3","views_label":"1248"},{"id":3523430,"title":"【专题】桂林龙舟侧翻17人亡 遇难人员家属:我眼睁睁看着儿子在水中挣扎","link":"lsapp://cn.ahurls.news/special?id=3523430","pics":["18/0422/5adbf3bcbec54.jpg"],"t":"url","type":"special","alias":"headline","pic_amount":0,"style":"single_fill","comment_amount":2,"source":"","type_sign":"专题","inner_news":1,"views":4075,"comment_amount_label":"2","views_label":"4075","pics_new":["18/0422/5adbf3bcbec54.jpg"]},{"id":3524380,"title":"水壶里发现避孕套 在烧水壶里尿尿 还有大妈竟用酒店热水壶做这种事...","link":"lsapp://cn.ahurls.news/news?id=3524380","pics":["appletrecommend/201804/5ade8fb8ec477.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":442,"comment_amount_label":"2","views_label":"442"},{"id":3524340,"title":"合肥城区示范性菜市场有奖征集 提档升级\u201c金点子\u201d及标识(Logo)等你来定","link":"lsapp://cn.ahurls.news/news?id=3524340","pics":["appletrecommend/201804/5ade8a4720eff.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":316,"comment_amount_label":"0","views_label":"316"},{"id":3524246,"title":"18岁女孩称被合租女生带回的男生砍毁容 左脸缝200多针","link":"lsapp://cn.ahurls.news/image_news?id=3524246","pics":["special/tuku/201804/5ade6e4db78b193298.jpg","special/tuku/201804/5ade6e4da76c711305.jpg","special/tuku/201804/5ade6e4d84c1e32717.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":1,"source":"","type_sign":"","inner_news":1,"views":1965,"comment_amount_label":"1","views_label":"1965","pics_new":["special/tuku/201804/5ade6e4db78b193298.jpg","special/tuku/201804/5ade6e4da76c711305.jpg","special/tuku/201804/5ade6e4d84c1e32717.jpg"]},{"id":3524118,"title":"上周合肥4盘开盘推500余套房源 网传经开某盘将加推超4000组客户预约","link":"lsapp://cn.ahurls.news/news?id=3524118","pics":["appletrecommend/201804/5ade6414ef95f.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":1,"source":"","type_sign":"","inner_news":1,"views":867,"comment_amount_label":"1","views_label":"867"},{"id":3524224,"title":"合肥7家A级景区获评\u201c平安景区\u201d 包公园已连续两年获此殊荣","link":"lsapp://cn.ahurls.news/news?id=3524224","pics":["appletrecommend/201804/5ade639f47cd9.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":1,"source":"","type_sign":"","inner_news":1,"views":718,"comment_amount_label":"1","views_label":"718"},{"id":3522438,"title":"【专题】五一还去挤黄山?这才是合肥人假期最值得去的9个地方!","link":"lsapp://cn.ahurls.news/special?id=3522438","pics":["18/0419/5ad85e298287a.jpg"],"t":"url","type":"special","alias":"headline","pic_amount":0,"style":"single_fill","comment_amount":2,"source":"","type_sign":"专题","inner_news":1,"views":3875,"comment_amount_label":"2","views_label":"3875","pics_new":["18/0419/5ad85e298287a.jpg"]},{"id":3524350,"title":"安徽将建立教师个人信用制度 建立师德考核\u201c负面清单\u201d","link":"lsapp://cn.ahurls.news/news?id=3524350","pics":["appletrecommend/201804/5ade989c2758d.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":353,"comment_amount_label":"0","views_label":"353"},{"id":3524068,"title":"合肥兵哥哥们的爱情故事 泪目!异地军恋那些事儿","link":"lsapp://cn.ahurls.news/news?id=3524068","pics":["appletrecommend/201804/5ade64496d7a0.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":1022,"comment_amount_label":"2","views_label":"1022"},{"id":3524391,"title":"25岁小伙如何月\u201c赚\u201d100万?肥西一男子信了!","link":"lsapp://cn.ahurls.news/image_news?id=3524391","pics":["special/tuku/201804/5ade8d81a6b8f80659.jpg","special/tuku/201804/5ade8d81be67582864.jpg","special/tuku/201804/5ade8d81e18cf26738.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":1507,"comment_amount_label":"0","views_label":"1507","pics_new":["special/tuku/201804/5ade8d81a6b8f80659.jpg"]},{"id":3524237,"title":"合肥2家开发商因拒绝公积金贷款 被要求限期改正","link":"lsapp://cn.ahurls.news/news?id=3524237","pics":["appletrecommend/201804/5ade69aad18a1.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":1,"source":"","type_sign":"","inner_news":1,"views":931,"comment_amount_label":"1","views_label":"931"},{"id":3524295,"title":"突发!广东KTV火灾致18死5伤 初步调查系人为纵火","link":"lsapp://cn.ahurls.news/news?id=3524295","pics":["appletrecommend/201804/5ade929e082b2.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":1,"source":"","type_sign":"","inner_news":1,"views":1039,"comment_amount_label":"1","views_label":"1039"},{"id":3524234,"title":"过期药毒性惊人!误服威胁生命 竟有人3折回收后卖到农村、小诊所","link":"lsapp://cn.ahurls.news/news?id=3524234","pics":["appletrecommend/201804/5ade673140628.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":2,"source":"","type_sign":"","inner_news":1,"views":1763,"comment_amount_label":"2","views_label":"1763"},{"id":3524433,"title":"小乌龟\u201c成精了\u201d?色彩丰富还有卡通造型 8块1只!","link":"lsapp://cn.ahurls.news/image_news?id=3524433","pics":["special/tuku/201804/5ade9163920d570240.jpg","special/tuku/201804/5ade9163d04bd20937.jpg","special/tuku/201804/5ade9163eb66044417.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":858,"comment_amount_label":"0","views_label":"858","pics_new":["special/tuku/201804/5ade9163920d570240.jpg"]},{"id":3524516,"title":"河南36名高中生未按时就寝遭劝退 教体局回应:校方处理过激","link":"lsapp://cn.ahurls.news/news?id=3524516","pics":["appletrecommend/201804/5adea41b4d356.png"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":84,"comment_amount_label":"0","views_label":"84"},{"id":3524509,"title":"少女洗澡煤气爆炸全身90%特重烧伤 17岁高二女孩忍痛报警","link":"lsapp://cn.ahurls.news/news?id=3524509","pics":["appletrecommend/201804/5adea3cf0523e.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":2306,"comment_amount_label":"0","views_label":"2306"},{"id":3524394,"title":"合肥:擅自设置入河排污口将被追责 县级以上政府需两月一检","link":"lsapp://cn.ahurls.news/news?id=3524394","pics":["appletrecommend/201804/5adea386e023f.jpg"],"t":"url","type":"normal","alias":"headline","pic_amount":0,"style":"single_right","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":251,"comment_amount_label":"0","views_label":"251"},{"id":3524523,"title":"泰国男子直播打女友 因欠债压力大 怀疑被劈腿","link":"lsapp://cn.ahurls.news/image_news?id=3524523","pics":["special/tuku/201804/5adea1f93bd8f63280.jpg","special/tuku/201804/5adea1f8af17149308.jpg","special/tuku/201804/5adea1f8c609f10899.jpg"],"t":"url","type":"images","alias":"headline","pic_amount":3,"style":"multi","comment_amount":0,"source":"","type_sign":"","inner_news":1,"views":1507,"comment_amount_label":"0","views_label":"1507","pics_new":["special/tuku/201804/5adea1f93bd8f63280.jpg"]}]
         * extras : {"slider":[{"id":3524270,"pic":"18/0424/5ade8cee6a463.jpg","link":"lsapp://cn.ahurls.news/news?id=3524270","t":"url","inner_news":1,"title":"5月合肥杂技、音乐剧轮番上演","type":"nomal","type_sign":""},{"id":3524248,"pic":"18/0424/5ade70d2452d1.jpg","link":"lsapp://cn.ahurls.news/news?id=3524248","t":"url","inner_news":1,"title":"合肥水源故里小镇项目初步规划出炉","type":"nomal","type_sign":""},{"id":3524128,"pic":"18/0423/5addcfe577447.jpg","link":"lsapp://cn.ahurls.news/news?id=3524128","t":"url","inner_news":1,"title":"合肥2018义务教育招生方案5月出台","type":"nomal","type_sign":""},{"id":3523709,"pic":"18/0423/5add7461af5b5.jpg","link":"lsapp://cn.ahurls.news/news?id=3523709","t":"url","inner_news":1,"title":"安徽6批次不合格酒被下架召回","type":"nomal","type_sign":""},{"id":3516306,"pic":"18/0408/5ac9e1309834b.jpg","link":"lsapp://cn.ahurls.news/news?id=3516306","t":"url","inner_news":1,"title":"3月份勋章积分奖励名单出炉啦!","type":"nomal","type_sign":""}]}
         * bindtips :
         */

        private int page;
        private int perpage;
        private int max_page;
        private int total;
        private ExtrasBean extras;
        private String bindtips;
        private List<DataBean> data;

        public int getPage() {
            return page;
        }

        public void setPage(int page) {
            this.page = page;
        }

        public int getPerpage() {
            return perpage;
        }

        public void setPerpage(int perpage) {
            this.perpage = perpage;
        }

        public int getMax_page() {
            return max_page;
        }

        public void setMax_page(int max_page) {
            this.max_page = max_page;
        }

        public int getTotal() {
            return total;
        }

        public void setTotal(int total) {
            this.total = total;
        }

        public ExtrasBean getExtras() {
            return extras;
        }

        public void setExtras(ExtrasBean extras) {
            this.extras = extras;
        }

        public String getBindtips() {
            return bindtips;
        }

        public void setBindtips(String bindtips) {
            this.bindtips = bindtips;
        }

        public List<DataBean> getData() {
            return data;
        }

        public void setData(List<DataBean> data) {
            this.data = data;
        }

        public static class ExtrasBean {
            private List<SliderBean> slider;

            public List<SliderBean> getSlider() {
                return slider;
            }

            public void setSlider(List<SliderBean> slider) {
                this.slider = slider;
            }

            public static class SliderBean {
                /**
                 * id : 3524270
                 * pic : 18/0424/5ade8cee6a463.jpg
                 * link : lsapp://cn.ahurls.news/news?id=3524270
                 * t : url
                 * inner_news : 1
                 * title : 5月合肥杂技、音乐剧轮番上演
                 * type : nomal
                 * type_sign :
                 */

                private int id;
                private String pic;
                private String link;
                private String t;
                private int inner_news;
                private String title;
                private String type;
                private String type_sign;

                public int getId() {
                    return id;
                }

                public void setId(int id) {
                    this.id = id;
                }

                public String getPic() {
                    return pic;
                }

                public void setPic(String pic) {
                    this.pic = pic;
                }

                public String getLink() {
                    return link;
                }

                public void setLink(String link) {
                    this.link = link;
                }

                public String getT() {
                    return t;
                }

                public void setT(String t) {
                    this.t = t;
                }

                public int getInner_news() {
                    return inner_news;
                }

                public void setInner_news(int inner_news) {
                    this.inner_news = inner_news;
                }

                public String getTitle() {
                    return title;
                }

                public void setTitle(String title) {
                    this.title = title;
                }

                public String getType() {
                    return type;
                }

                public void setType(String type) {
                    this.type = type;
                }

                public String getType_sign() {
                    return type_sign;
                }

                public void setType_sign(String type_sign) {
                    this.type_sign = type_sign;
                }
            }
        }

        public static class DataBean {
            /**
             * id : 3524385
             * title : 合肥城市总体规划编制大调研工作启动 今年12月完成总规纲要初步成果
             * link : lsapp://cn.ahurls.news/news?id=3524385
             * pics : ["appletrecommend/201804/5ade91c99a715.jpg"]
             * t : url
             * type : normal
             * alias : headline
             * pic_amount : 0
             * style : single_right
             * comment_amount : 0
             * source :
             * type_sign :
             * inner_news : 1
             * views : 394
             * comment_amount_label : 0
             * views_label : 394
             * pics_new : ["special/tuku/201804/5add9971130ea73397.jpg"]
             */

            private int id;
            private String title;
            private String link;
            private String t;
            private String type;
            private String alias;
            private int pic_amount;
            private String style;
            private int comment_amount;
            private String source;
            private String type_sign;
            private int inner_news;
            private int views;
            private String comment_amount_label;
            private String views_label;
            private List<String> pics;
            private List<String> pics_new;

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }

            public String getLink() {
                return link;
            }

            public void setLink(String link) {
                this.link = link;
            }

            public String getT() {
                return t;
            }

            public void setT(String t) {
                this.t = t;
            }

            public String getType() {
                return type;
            }

            public void setType(String type) {
                this.type = type;
            }

            public String getAlias() {
                return alias;
            }

            public void setAlias(String alias) {
                this.alias = alias;
            }

            public int getPic_amount() {
                return pic_amount;
            }

            public void setPic_amount(int pic_amount) {
                this.pic_amount = pic_amount;
            }

            public String getStyle() {
                return style;
            }

            public void setStyle(String style) {
                this.style = style;
            }

            public int getComment_amount() {
                return comment_amount;
            }

            public void setComment_amount(int comment_amount) {
                this.comment_amount = comment_amount;
            }

            public String getSource() {
                return source;
            }

            public void setSource(String source) {
                this.source = source;
            }

            public String getType_sign() {
                return type_sign;
            }

            public void setType_sign(String type_sign) {
                this.type_sign = type_sign;
            }

            public int getInner_news() {
                return inner_news;
            }

            public void setInner_news(int inner_news) {
                this.inner_news = inner_news;
            }

            public int getViews() {
                return views;
            }

            public void setViews(int views) {
                this.views = views;
            }

            public String getComment_amount_label() {
                return comment_amount_label;
            }

            public void setComment_amount_label(String comment_amount_label) {
                this.comment_amount_label = comment_amount_label;
            }

            public String getViews_label() {
                return views_label;
            }

            public void setViews_label(String views_label) {
                this.views_label = views_label;
            }

            public List<String> getPics() {
                return pics;
            }

            public void setPics(List<String> pics) {
                this.pics = pics;
            }

            public List<String> getPics_new() {
                return pics_new;
            }

            public void setPics_new(List<String> pics_new) {
                this.pics_new = pics_new;
            }
        }
    }

ListViewAdapter

package zhanghaijiao.bawei.com.day10_demo3;

import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;

import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private PullToRefreshScrollView psv;

    private int pageIndex=1;
    private int operType=1;//1:刷新 2:加载更多

    private String myurl="http://365jia.cn/news/api3/365jia/news/headline?page="+pageIndex;

    private  List<ResultData.DataBeanX.DataBean> datas=new ArrayList<>();
    private ListViewAdapter adapter;
    private ListView listView;
    private ViewPager viewPager;
    private List<String> imgUrls=new ArrayList<>();
    private LinearLayout linPoint;

    private List<ImageView> lists=new ArrayList<>();
    private Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            int cIndex=viewPager.getCurrentItem();
            cIndex++;
            viewPager.setCurrentItem(cIndex);

            //改变指示器
            setSelectedPoint(cIndex%lists.size());


            sendEmptyMessageDelayed(0,1000);

        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        psv = findViewById(R.id.psv);
        listView = findViewById(R.id.lv);
        viewPager = findViewById(R.id.vp);
        linPoint = findViewById(R.id.lin_point);




        //初使化 pullToRefreshScrollView
        initPsv();


        //请求网络数据
        requestNetData();





    }

    private void requestNetData() {
        new MyTask().execute(myurl);

    }
    class MyTask extends AsyncTask<String,Void,String> {

        @Override
        protected String doInBackground(String... strings) {
            try {
                URL url=new URL(strings[0]);
                HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

                urlConnection.setRequestMethod("GET");
                urlConnection.setReadTimeout(5000);
                urlConnection.setConnectTimeout(5000);

                if(urlConnection.getResponseCode()==200){
                    InputStream inputStream = urlConnection.getInputStream();

                    String s = streamToString(inputStream);
                    return s;



                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);

            Gson gson=new Gson();
            ResultData resultData = gson.fromJson(s, ResultData.class);
            //新请求下来的数据
            List<ResultData.DataBeanX.DataBean> data = resultData.getData().getData();

            //展示轮播图
            showPics(data);


            if(operType==1){
                datas.clear();//清空
            }
            datas.addAll(data);

            setAdapter();

            //关闭头尾布局
            psv.onRefreshComplete();





        }
    }

    private void showPics(List<ResultData.DataBeanX.DataBean> data) {
        imgUrls.clear();
        //为轮播图添加地址
        imgUrls.add("http://365jia.cn/uploads/"+data.get(0).getPics().get(0));
        imgUrls.add("http://365jia.cn/uploads/"+data.get(1).getPics().get(0));
        imgUrls.add("http://365jia.cn/uploads/"+data.get(2).getPics().get(0));

        MyVpAdapter adapter=new MyVpAdapter(imgUrls,MainActivity.this);
        viewPager.setAdapter(adapter);

        //初使化指示器
        initPoint();


        //发送消息,实现自动轮播
        mHandler.sendEmptyMessageDelayed(0,1000);
    }

    //设置选中的小圆点
    private  void setSelectedPoint(int pageIndex){
        for (int i = 0; i <lists.size() ; i++) {
            if(i==pageIndex){
                lists.get(i).setImageResource(R.drawable.point_selected);
            }else {
                lists.get(i).setImageResource(R.drawable.point_unselected);
            }

        }

    }

    private void initPoint() {
        for (int i = 0; i <imgUrls.size() ; i++) {
            ImageView imageView=new ImageView(this);
            //设置它的布局参数
            LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
            params.setMargins(0,0,10,0);//设置右边的间隔
            if(i==0){
                imageView.setImageResource(R.drawable.point_selected);//选中的小圆点
            }else{
                imageView.setImageResource(R.drawable.point_unselected);
            }
            linPoint.addView(imageView,params);

            lists.add(imageView);
        }

    }

    public void setAdapter(){
        if (adapter == null) {
            adapter = new ListViewAdapter(datas,MainActivity.this);
            listView.setAdapter(adapter);
        }else {
            adapter.notifyDataSetChanged();
        }

    }

    /**
     * 将流转换成String
     * @param stream
     */
    private String streamToString(InputStream stream) {
        StringBuilder sbuilder=new StringBuilder();
        String str;
        BufferedReader reader=new BufferedReader(new InputStreamReader(stream));

        try {
            while ((str=reader.readLine())!=null){
                sbuilder.append(str);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  sbuilder.toString();

    }

    private void initPsv() {
        //1.设置模式
        psv.setMode(PullToRefreshBase.Mode.BOTH);
        //2.设置监听
        psv.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> pullToRefreshBase) {
                //刷新回调
                operType=1;
                pageIndex=1;
                myurl="http://365jia.cn/news/api3/365jia/news/headline?page="+pageIndex;
                requestNetData();

            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> pullToRefreshBase) {
                //加载回调
                operType=2;
                pageIndex++;
                myurl="http://365jia.cn/news/api3/365jia/news/headline?page="+pageIndex;
                requestNetData();

            }
        });
    }
}

MyListView

package zhanghaijiao.bawei.com.day10_demo3;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

/**
 * Created by jane on 2018/4/24.
 */

public class MyListView extends ListView {
    public MyListView(Context context) {
        super(context);
    }

    public MyListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    //测量
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //重新计算高度
        int newHeight=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, newHeight);
    }
}

MyVpAdapter

package zhanghaijiao.bawei.com.day10_demo3;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;

import java.util.List;

/**
 * Created by jane on 2018/4/24.
 */

public class MyVpAdapter extends PagerAdapter {

    //数据源
    private List<String> urls;
    //上下文对象
    private Context context;

    private DisplayImageOptions options;

    public MyVpAdapter(List<String> urls, Context context) {
        this.urls = urls;
        this.context = context;
        this.options=new DisplayImageOptions.Builder()
                .cacheInMemory(true)//使用内存缓存
                .cacheOnDisk(true)//使用磁盘缓存
                .showImageOnLoading(R.mipmap.ic_launcher)//设置正在下载的图片
                .showImageForEmptyUri(R.mipmap.ic_launcher)//url为空或请求的资源不存在时
                .showImageOnFail(R.mipmap.ic_launcher)//下载失败时显示的图片
                .bitmapConfig(Bitmap.Config.RGB_565)//设置图片色彩模式  1px=2个字节  ARGB_8888 1px=4个字节   ARGB_4444 1px=2个字节  ALPHA_8 1px=1个字节
                .imageScaleType(ImageScaleType.EXACTLY)//设置图片的缩放模式
                .build();
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView=new ImageView(context);
        //下载图片
        ImageLoader.getInstance().displayImage(urls.get(position%urls.size()),imageView,options);

        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //super.destroyItem(container, position, object);
        container.removeView((View)object);
    }
}

MyApplication

package zhanghaijiao.bawei.com.day10_demo3;

import android.app.Application;
import android.os.Environment;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.io.File;

/**
 * Created by jane on 2018/4/17.
 */

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        //自定义图片的缓存路径
        File cachefile=new File( Environment.getExternalStorageDirectory().getPath()+"/abc");


        ImageLoaderConfiguration configuration=new ImageLoaderConfiguration.Builder(this)
                .memoryCacheExtraOptions(480, 800)//缓存图片最大的长和宽
                .threadPoolSize(2)//线程池的数量
                .threadPriority(4)
                .memoryCacheSize(2*1024*1024)//设置内存缓存区大小
                .diskCacheSize(20*1024*1024)//设置sd卡缓存区大小
                .diskCache(new UnlimitedDiscCache(cachefile))//自定义缓存目录
                .writeDebugLogs()//打印日志内容
                .diskCacheFileNameGenerator(new Md5FileNameGenerator())//给缓存的文件名进行md5加密处理
                .build();
        ImageLoader.getInstance().init(configuration);

    }
}

item

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv"
     />
</RelativeLayout>

pull

 

 

compile ‘com.github.userswlwork:pull-to-refresh:1.0.0‘

以上是关于上下拉刷新 轮播图 listview的主要内容,如果未能解决你的问题,请参考以下文章

网页HTML代码制作轮播图效果

Android轮播图封装,下拉刷新相结合

jquery图片上下轮播的问题,怎么实现自动轮播?

轮播图2(上下轮播)

手机的轮播图可以用jquery来做吗

用js函数封装一个上下滑动的轮播图,调用任意