listview多条目加载

来源:互联网 发布:qq2012透明皮肤软件 编辑:程序博客网 时间:2024/06/05 17:15

//activity_main.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout    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" tools:context="com.example.listview.MainActivity">    <ListView        android:id="@+id/main_listview"        android:layout_width="match_parent"        android:layout_height="match_parent"/></RelativeLayout>

//item_buttom_layout.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <TextView        android:id="@+id/item_button_text_title"        android:layout_width="match_parent"        android:layout_height="wrap_content" />    <ImageView        android:id="@+id/item_button_image_view"        android:layout_width="match_parent"        android:layout_height="200dp" /></LinearLayout>

//item_left_layout.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <ImageView        android:id="@+id/item_left_image_view"        android:layout_width="100dp"        android:layout_height="100dp" />    <TextView        android:id="@+id/item_left_text_title"        android:layout_width="wrap_content"        android:layout_height="wrap_content" /></LinearLayout>

//item_right_layout.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <TextView        android:id="@+id/item_right_text_title"        android:layout_width="10dp"        android:layout_weight="1"        android:layout_height="wrap_content" />    <ImageView        android:id="@+id/item_right_image_view"        android:layout_width="100dp"        android:layout_height="100dp" /></LinearLayout>

//item_title_layout.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <TextView        android:id="@+id/item_title_text_title"        android:layout_width="wrap_content"        android:layout_height="wrap_content" /></LinearLayout>

//DataDataBean

package com.example.listview;import java.util.List;/** * Created by 123 on 2017/10/25. */public class DataDataBean {    /**     * reason : 请求成功     * result : {"list":[{"id":"wechat_20171025017911","title":"每日捧腹段子精选:这祖传的手艺怎么能丢,以前你爷爷也是这么打我的。。。","source":"捧腹笑话","firstImg":"","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025017911"},{"id":"wechat_20171025020879","title":"@所有施工单位,9月大气污染\u201c黑名单\u201d曝光,你不进来看看?","source":"遵义晚报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-55933205.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020879"},{"id":"wechat_20171025020824","title":"李先生的新业务伙伴,帮他解决了\u201c烦心事\u201d","source":"每日经济新闻","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009380.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020824"},{"id":"wechat_20171025020825","title":"李先生的新业务伙伴,帮他解决了\u201c烦心事\u201d","source":"每日经济新闻","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009380.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020825"},{"id":"wechat_20171025020880","title":"习近平当选总书记","source":"人民日报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-28158232.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020880"},{"id":"wechat_20171025020817","title":"韩粉们别再瞎吹了,这剧哪里值9.1分?丨毒药头条","source":"毒药","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-9595026.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020817"},{"id":"wechat_20171025020816","title":"韩粉们别再瞎吹了,这剧哪里值9.1分?丨毒药头条","source":"毒药","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-9595026.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020816"},{"id":"wechat_20171025020940","title":"KO甜蜜暴击走出\u201c失恋\u201d阴霾,护肤测评干货教你颜值up自信撩男神!","source":"瑞丽网","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-17029942.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020940"},{"id":"wechat_20171025020937","title":"只能保湿?解锁牛油果眼霜的隐藏技能","source":"瑞丽网","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-17029942.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020937"},{"id":"wechat_20171025020870","title":"今天下午,新时代的无锡\u201c五福\u201d故事,给你惊喜!","source":"FM926无锡梁溪之声","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009462.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020870"},{"id":"wechat_20171025020832","title":"党的新一届中央领导机构诞生了!","source":"FM926无锡梁溪之声","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56006911.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020832"},{"id":"wechat_20171025020830","title":"潮流范 | 复古条绒裤混搭不要太时髦,各种配色更让人眼前一亮","source":"瑞丽网","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-17029942.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020830"},{"id":"wechat_20171025020829","title":"点睛 | 范冰冰唐艺昕靠个性手袋撑起整个造型!全黑不再呆板","source":"瑞丽网","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-17029942.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020829"},{"id":"wechat_20171025020823","title":"更新换代 | 马丁靴帅气人设\u201c崩塌\u201d,俏皮感十足周冬雨娜扎抢着穿","source":"瑞丽网","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-17029942.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020823"},{"id":"wechat_20171025020835","title":"【景漂·景归】刘瑞华:让中华瓷器工艺和文化给人们生活带来愉悦和美好","source":"景德镇日报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-55021182.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020835"},{"id":"wechat_20171025020885","title":"被这个超酷的图书馆刷屏!网友惊呼:原来\u201c知识的海洋\u201d长这样\u2026","source":"陕西都市快报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009452.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020885"},{"id":"wechat_20171025020863","title":"你娃上幼儿园一个月多少钱?西安民办幼儿园收费高不高?市物价局出手了!","source":"陕西都市快报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009452.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020863"},{"id":"wechat_20171025020882","title":"这项传统工艺在三明这个家族已传承上百年,至今仍有人坚守","source":"三明日报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009507.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020882"},{"id":"wechat_20171025020958","title":"党的新一届中央领导机构诞生了!","source":"蛇口消息报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009778.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020958"},{"id":"wechat_20171025020952","title":"重阳节,大南山、塘朗山登山路线示意图发布,你要这样做","source":"蛇口消息报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-48646111.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020952"},{"id":"wechat_20171025020941","title":"定深圳了!深圳(南山区)首届螃蟹狂欢节,10月27日盛大开幕!","source":"蛇口消息报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-49988231.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020941"},{"id":"wechat_20171025020926","title":"全市出让最多的土地!就在南山这个地方...","source":"蛇口消息报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-48646111.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020926"},{"id":"wechat_20171025020917","title":"【健康】各种疾病的早期信号,全都在这里!知道了省钱又救命!","source":"三明日报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-55511571.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020917"},{"id":"wechat_20171025020423","title":"5000马力和800马力的区别是什么?八百米赛跑先让你5秒!","source":"腾讯汽车","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-55422140.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020423"},{"id":"wechat_20171025020406","title":"本田全新小SUV要火!8万起步/油耗不到5L 有些SUV绝对遭殃!","source":"腾讯汽车","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-55422140.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020406"},{"id":"wechat_20171025019950","title":"文殊法堂 | 智慧与解脱:《维摩诘经》释论(五十一)","source":"五台山佛教","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-28168446.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025019950"},{"id":"wechat_20171025019945","title":"清涼学堂 | 佛教常用器物:拂 子","source":"五台山佛教","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-28168446.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025019945"},{"id":"wechat_20171025020433","title":"伊藤润二最害怕什么?| 正午·视觉","source":"正午故事","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56008521.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020433"},{"id":"wechat_20171025020415","title":"连环画之世界瑰宝,12册《水浒传》连环画重出江湖","source":"真历史","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56008468.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020415"},{"id":"wechat_20171025019524","title":"人生最难是什么?(大实话)","source":"梵心佛语录","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56006643.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025019524"}],"totalPage":5915,"ps":30,"pno":1}     * error_code : 0     */    private String reason;    private ResultBean result;    private int error_code;    public String getReason() {        return reason;    }    public void setReason(String reason) {        this.reason = reason;    }    public ResultBean getResult() {        return result;    }    public void setResult(ResultBean result) {        this.result = result;    }    public int getError_code() {        return error_code;    }    public void setError_code(int error_code) {        this.error_code = error_code;    }    public static class ResultBean {        /**         * list : [{"id":"wechat_20171025017911","title":"每日捧腹段子精选:这祖传的手艺怎么能丢,以前你爷爷也是这么打我的。。。","source":"捧腹笑话","firstImg":"","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025017911"},{"id":"wechat_20171025020879","title":"@所有施工单位,9月大气污染\u201c黑名单\u201d曝光,你不进来看看?","source":"遵义晚报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-55933205.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020879"},{"id":"wechat_20171025020824","title":"李先生的新业务伙伴,帮他解决了\u201c烦心事\u201d","source":"每日经济新闻","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009380.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020824"},{"id":"wechat_20171025020825","title":"李先生的新业务伙伴,帮他解决了\u201c烦心事\u201d","source":"每日经济新闻","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009380.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020825"},{"id":"wechat_20171025020880","title":"习近平当选总书记","source":"人民日报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-28158232.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020880"},{"id":"wechat_20171025020817","title":"韩粉们别再瞎吹了,这剧哪里值9.1分?丨毒药头条","source":"毒药","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-9595026.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020817"},{"id":"wechat_20171025020816","title":"韩粉们别再瞎吹了,这剧哪里值9.1分?丨毒药头条","source":"毒药","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-9595026.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020816"},{"id":"wechat_20171025020940","title":"KO甜蜜暴击走出\u201c失恋\u201d阴霾,护肤测评干货教你颜值up自信撩男神!","source":"瑞丽网","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-17029942.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020940"},{"id":"wechat_20171025020937","title":"只能保湿?解锁牛油果眼霜的隐藏技能","source":"瑞丽网","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-17029942.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020937"},{"id":"wechat_20171025020870","title":"今天下午,新时代的无锡\u201c五福\u201d故事,给你惊喜!","source":"FM926无锡梁溪之声","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009462.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020870"},{"id":"wechat_20171025020832","title":"党的新一届中央领导机构诞生了!","source":"FM926无锡梁溪之声","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56006911.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020832"},{"id":"wechat_20171025020830","title":"潮流范 | 复古条绒裤混搭不要太时髦,各种配色更让人眼前一亮","source":"瑞丽网","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-17029942.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020830"},{"id":"wechat_20171025020829","title":"点睛 | 范冰冰唐艺昕靠个性手袋撑起整个造型!全黑不再呆板","source":"瑞丽网","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-17029942.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020829"},{"id":"wechat_20171025020823","title":"更新换代 | 马丁靴帅气人设\u201c崩塌\u201d,俏皮感十足周冬雨娜扎抢着穿","source":"瑞丽网","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-17029942.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020823"},{"id":"wechat_20171025020835","title":"【景漂·景归】刘瑞华:让中华瓷器工艺和文化给人们生活带来愉悦和美好","source":"景德镇日报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-55021182.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020835"},{"id":"wechat_20171025020885","title":"被这个超酷的图书馆刷屏!网友惊呼:原来\u201c知识的海洋\u201d长这样\u2026","source":"陕西都市快报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009452.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020885"},{"id":"wechat_20171025020863","title":"你娃上幼儿园一个月多少钱?西安民办幼儿园收费高不高?市物价局出手了!","source":"陕西都市快报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009452.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020863"},{"id":"wechat_20171025020882","title":"这项传统工艺在三明这个家族已传承上百年,至今仍有人坚守","source":"三明日报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009507.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020882"},{"id":"wechat_20171025020958","title":"党的新一届中央领导机构诞生了!","source":"蛇口消息报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56009778.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020958"},{"id":"wechat_20171025020952","title":"重阳节,大南山、塘朗山登山路线示意图发布,你要这样做","source":"蛇口消息报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-48646111.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020952"},{"id":"wechat_20171025020941","title":"定深圳了!深圳(南山区)首届螃蟹狂欢节,10月27日盛大开幕!","source":"蛇口消息报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-49988231.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020941"},{"id":"wechat_20171025020926","title":"全市出让最多的土地!就在南山这个地方...","source":"蛇口消息报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-48646111.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020926"},{"id":"wechat_20171025020917","title":"【健康】各种疾病的早期信号,全都在这里!知道了省钱又救命!","source":"三明日报","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-55511571.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020917"},{"id":"wechat_20171025020423","title":"5000马力和800马力的区别是什么?八百米赛跑先让你5秒!","source":"腾讯汽车","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-55422140.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020423"},{"id":"wechat_20171025020406","title":"本田全新小SUV要火!8万起步/油耗不到5L 有些SUV绝对遭殃!","source":"腾讯汽车","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-55422140.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020406"},{"id":"wechat_20171025019950","title":"文殊法堂 | 智慧与解脱:《维摩诘经》释论(五十一)","source":"五台山佛教","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-28168446.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025019950"},{"id":"wechat_20171025019945","title":"清涼学堂 | 佛教常用器物:拂 子","source":"五台山佛教","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-28168446.static/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025019945"},{"id":"wechat_20171025020433","title":"伊藤润二最害怕什么?| 正午·视觉","source":"正午故事","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56008521.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020433"},{"id":"wechat_20171025020415","title":"连环画之世界瑰宝,12册《水浒传》连环画重出江湖","source":"真历史","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56008468.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025020415"},{"id":"wechat_20171025019524","title":"人生最难是什么?(大实话)","source":"梵心佛语录","firstImg":"http://zxpic.gtimg.com/infonew/0/wechat_pics_-56006643.jpg/640","mark":"","url":"http://v.juhe.cn/weixin/redirect?wid=wechat_20171025019524"}]         * totalPage : 5915         * ps : 30         * pno : 1         */        private int totalPage;        private int ps;        private int pno;        private List<ListBean> list;        public int getTotalPage() {            return totalPage;        }        public void setTotalPage(int totalPage) {            this.totalPage = totalPage;        }        public int getPs() {            return ps;        }        public void setPs(int ps) {            this.ps = ps;        }        public int getPno() {            return pno;        }        public void setPno(int pno) {            this.pno = pno;        }        public List<ListBean> getList() {            return list;        }        public void setList(List<ListBean> list) {            this.list = list;        }        public static class ListBean {            /**             * id : wechat_20171025017911             * title : 每日捧腹段子精选:这祖传的手艺怎么能丢,以前你爷爷也是这么打我的。。。             * source : 捧腹笑话             * firstImg :             * mark :             * url : http://v.juhe.cn/weixin/redirect?wid=wechat_20171025017911             */            private String id;            private String title;            private String source;            private String firstImg;            private String mark;            private String url;            public String getId() {                return id;            }            public void setId(String id) {                this.id = id;            }            public String getTitle() {                return title;            }            public void setTitle(String title) {                this.title = title;            }            public String getSource() {                return source;            }            public void setSource(String source) {                this.source = source;            }            public String getFirstImg() {                return firstImg;            }            public void setFirstImg(String firstImg) {                this.firstImg = firstImg;            }            public String getMark() {                return mark;            }            public void setMark(String mark) {                this.mark = mark;            }            public String getUrl() {                return url;            }            public void setUrl(String url) {                this.url = url;            }        }    }}

//MainActivity

package com.example.listview;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.os.Handler;import android.os.Message;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.ImageView;import android.widget.ListView;import com.google.gson.Gson;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.URL;import java.util.ArrayList;import java.util.List;public class MainActivity extends AppCompatActivity {    private ListView main_listview;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        main_listview = (ListView) findViewById(R.id.main_listview);        MyTack myTack = new MyTack(new MyTack.Icallbacks() {            @Override            public void updateUiByjson(String jsonstr) {                Gson gson = new Gson();                DataDataBean result = gson.fromJson(jsonstr, DataDataBean.class);                //得到要显示的数据源                List<DataDataBean.ResultBean.ListBean> datas = result.getResult().getList();                main_listview.setAdapter(new MyAdapter(datas,MainActivity.this));            }        });        myTack.execute("http://v.juhe.cn/weixin/query?key=88f7bbc507e3ecacfaeab2b47dd8936f&ps=30");    }}

//MyAdapter

package com.example.listview;import android.content.Context;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.TextView;import com.nostra13.universalimageloader.core.ImageLoader;import java.util.List;/** * Created by 123 on 2017/10/25. */public class MyAdapter extends BaseAdapter{    //定义两种类型 int类型,注意: 定义的数字 不能大于等于 getViewTypeCount 返回的数字    int TYTLE_ONLY = 0;//只有文字的形式    int IMAGE_LEFT = 1;//表示图片在左边,文字在右边    int IMAGE_RIGHT = 2;//表示图片在右边,文字在左边    int IMAGE_BOTTOM = 3;//表示文字在上边,图片在下面    private List<DataDataBean.ResultBean.ListBean> list;    private Context context;    public MyAdapter(List<DataDataBean.ResultBean.ListBean> list, Context context) {        this.list = list;        this.context = context;    }    @Override    public int getCount() {        return list.size();    }    @Override    public Object getItem(int position) {        return list.get(position);    }    @Override    public long getItemId(int position) {        return position;    }    //得到视图类型的总数    @Override    public int getViewTypeCount() {        return 4;    }    //根据position 当前条目 ,去获取要显示的视图类型,返回值 int    @Override    public int getItemViewType(int position) {        //根据数据内容去判断得到显示的类型        /**         * if(position%4==0) 则表示加载   TYTLE_ONLY  这种类型的视图         if(position%4==1) 则表示加载   IMAGE_LEFT  这种类型的视图         if(position%4==2) 则表示加载   IMAGE_RIGHT  这种类型的视图         if(position%4==3) 则表示加载   IMAGE_BOTTOM  这种类型的视图         */        if (position % 4 == 0) {            return TYTLE_ONLY;        } else if (position % 4 == 1) {            return IMAGE_LEFT;        } else if (position % 4 == 2) {            return IMAGE_RIGHT;        } else if (position % 4 == 3) {            return IMAGE_BOTTOM;        }        return TYTLE_ONLY;    }    @Override    public View getView(int position, View convertView, ViewGroup parent) {        //首先要根据position得到显示的类型        int type = getItemViewType(position);        switch (type) {            case 0:                HolderOne holderOne;                if (convertView == null) {                    convertView = View.inflate(context, R.layout.item_title_layout, null);                    holderOne = new HolderOne();                    holderOne.tvName = convertView.findViewById(R.id.item_title_text_title);                    convertView.setTag(holderOne);                } else {                    holderOne = (HolderOne) convertView.getTag();                }                holderOne.tvName.setText(list.get(position).getSource());                return convertView;            case 1:                HolderTwo holderTwo;                if (convertView == null) {                    convertView = View.inflate(context, R.layout.item_buttom_layout, null);                    holderTwo = new HolderTwo();                    holderTwo.tvName = convertView.findViewById(R.id.item_button_text_title);                    holderTwo.tvSex = convertView.findViewById(R.id.item_button_image_view);                    convertView.setTag(holderTwo);                } else {                    holderTwo = (HolderTwo) convertView.getTag();                }                holderTwo.tvName.setText(list.get(position).getSource());                ImageLoader.getInstance().displayImage(list.get(position).getFirstImg(), holderTwo.tvSex);                return convertView;            case 2:                HolderThree holderThree;                if (convertView == null) {                    convertView = View.inflate(context, R.layout.item_left_layout, null);                    holderThree = new HolderThree();                    holderThree.tvName = convertView.findViewById(R.id.item_left_text_title);                    holderThree.tvSex = convertView.findViewById(R.id.item_left_image_view);                    convertView.setTag(holderThree);                } else {                    holderThree = (HolderThree) convertView.getTag();                }                holderThree.tvName.setText(list.get(position).getSource());                ImageLoader.getInstance().displayImage(list.get(position).getFirstImg(), holderThree.tvSex);                return convertView;            case 3:                HolderFour holderFour;                if (convertView == null) {                    convertView = View.inflate(context, R.layout.item_right_layout, null);                    holderFour = new HolderFour();                    holderFour.tvName = convertView.findViewById(R.id.item_right_text_title);                    holderFour.tvSex = convertView.findViewById(R.id.item_right_image_view);                    convertView.setTag(holderFour);                } else {                    holderFour = (HolderFour) convertView.getTag();                }                holderFour.tvName.setText(list.get(position).getSource());                ImageLoader.getInstance().displayImage(list.get(position).getFirstImg(), holderFour.tvSex);                return convertView;        }        return null;    }    class HolderOne {        TextView tvName;    }    class HolderTwo {        TextView tvName;        ImageView tvSex;    }    class HolderThree {        TextView tvName;        ImageView tvSex;    }    class HolderFour {        TextView tvName;        ImageView tvSex;    }}

//MyApplication

package com.example.listview;import android.app.Application;import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;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 123 on 2017/10/25. */public class MyApplication extends Application{    @Override    public void onCreate() {        super.onCreate();        File cachefile=getExternalCacheDir();        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))//自定义缓存目录                .diskCache(new UnlimitedDiskCache(cachefile))                .writeDebugLogs()//打印日志内容                .diskCacheFileNameGenerator(new Md5FileNameGenerator())//给缓存的文件名进行md5加密处理                .build();        ImageLoader.getInstance().init(configuration);    }}

//MyTack

package com.example.listview;import android.os.AsyncTask;import java.io.IOException;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;/** * Created by 123 on 2017/10/25. */public class MyTack  extends AsyncTask<String,Void,String> {    private   Icallbacks icallbacks;    //将无参构造设置成私有的,使之在外部不能够调用    private  MyTack(){    }    public MyTack(Icallbacks icallbacks){        this.icallbacks=icallbacks;    }    @Override    protected String doInBackground(String... strings) {        String str="";        try {            URL url=new URL(strings[0]);            HttpURLConnection connection = (HttpURLConnection) url.openConnection();            connection.setRequestMethod("GET");            connection.setConnectTimeout(5000);            connection.setConnectTimeout(5000);            if(connection.getResponseCode()==200){                InputStream inputStream = connection.getInputStream();                str = StreamToString.streamToStr(inputStream, "utf-8");            }        } catch (MalformedURLException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        }        return str;    }    @Override    protected void onPostExecute(String s) {        super.onPostExecute(s);        icallbacks.updateUiByjson(s);    }    public  interface  Icallbacks{        void  updateUiByjson(String jsonstr);    }}

//StreamToString

package com.example.listview;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;/** * Created by 123 on 2017/10/25. */public class StreamToString {    public static String streamToStr(InputStream inputStream, String chartSet) {        StringBuilder builder = new StringBuilder();        try {            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, chartSet));            String con;            while ((con = br.readLine()) != null) {                builder.append(con);            }            br.close();            return builder.toString();        } catch (Exception e) {            e.printStackTrace();        }        return "";    }}
原创粉丝点击