欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

九宫格

程序员文章站 2022-06-14 13:30:39
...

activity_main

<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <GridView
        android:id="@+id/grid_view"
        android:numColumns="3"
        android:layout_width="match_parent"
        android:layout_height="290dp">
    </GridView>
    <android.support.v7.widget.RecyclerView
        android:layout_marginTop="75dp"
        android:id="@+id/recy_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>
</LinearLayout>

img_item

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:layout_height="wrap_content">
    <ImageView
        android:src="@mipmap/ic_launcher"
        android:id="@+id/img"
        android:layout_width="50dp"
        android:layout_height="50dp" />
</LinearLayout>

item_layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:layout_height="match_parent">
    <ImageView
        android:layout_margin="15dp"
        android:src="@drawable/ic_launcher_background"
        android:id="@+id/image_view"
        android:layout_width="250dp"
        android:layout_height="100dp" />
    <TextView
        android:layout_margin="15dp"
        android:id="@+id/text_view"
        android:text="帅"
        android:textSize="30sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

JiuBean

public class JiuBean {

    /**
     * msg :
     * code : 0
     * data : [{"cid":1,"createtime":"2017-10-10T19:41:39","icon":"http://120.27.23.105/images/category/shop.png","ishome":1,"name":"京东超市"},{"cid":2,"createtime":"2017-10-10T19:41:39","icon":"http://120.27.23.105/images/category/qqg.png","ishome":1,"name":"全球购"},{"cid":3,"createtime":"2017-10-10T19:45:11","icon":"http://120.27.23.105/images/category/phone.png","ishome":1,"name":"手机数码"},{"cid":5,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/man.png","ishome":1,"name":"男装"},{"cid":6,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/girl.png","ishome":1,"name":"女装"},{"cid":7,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/manshoe.png","ishome":1,"name":"男鞋"},{"cid":8,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/girlshoe.png","ishome":1,"name":"女鞋"},{"cid":9,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/shirt.png","ishome":1,"name":"内衣配饰"},{"cid":10,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/bag.png","ishome":1,"name":"箱包手袋"},{"cid":11,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/beauty.png","ishome":1,"name":"美妆个护"},{"cid":12,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/jewel.png","ishome":1,"name":"钟表珠宝"},{"cid":13,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/luxury.png","ishome":1,"name":"奢侈品"},{"cid":14,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/computer.png","ishome":1,"name":"电脑办公"},{"cid":15,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"家用电器"},{"cid":16,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"食品生鲜"},{"cid":17,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"酒水饮料"},{"cid":18,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"母婴童装"},{"cid":19,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"玩具乐器"},{"cid":20,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"医药保健"}]
     */

    private String msg;
    private String code;
    private List<DataBean> data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

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

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

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

    public static class DataBean {
        /**
         * cid : 1
         * createtime : 2017-10-10T19:41:39
         * icon : http://120.27.23.105/images/category/shop.png
         * ishome : 1
         * name : 京东超市
         */

        private int cid;
        private String createtime;
        private String icon;
        private int ishome;
        private String name;

        public int getCid() {
            return cid;
        }

        public void setCid(int cid) {
            this.cid = cid;
        }

        public String getCreatetime() {
            return createtime;
        }

        public void setCreatetime(String createtime) {
            this.createtime = createtime;
        }

        public String getIcon() {
            return icon;
        }

        public void setIcon(String icon) {
            this.icon = icon;
        }

        public int getIshome() {
            return ishome;
        }

        public void setIshome(int ishome) {
            this.ishome = ishome;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}

pRODUCT

public class Product {

    /**
     * status : 200
     * message : 获取餐馆列表成功
     * data : [{"_id":"5ac5af803714cc2d644f4615","id":32,"name":"麦当当的店","month_sales":194,"month_sales_tip":"月售194笔","wm_poi_score":3,"delivery_score":2.1,"quality_score":3.7,"pack_score":4.1,"food_score":1.1,"delivery_time_tip":"1525.9分钟","third_category":"中式简餐","pic_url":"http://p0.meituan.net/xianfu/fdd295e7650587269e0f1d7c35ba180c114177.jpg","shopping_time_start":"8:00","shopping_time_end":"24:00","min_price":10,"min_price_tip":"起送 ¥10","shipping_fee":0,"shipping_fee_tip":"配送 ¥0","bulletin":"理工短号615592(原大学生粗粮坊)做你身边最快的外卖!","address":"东莞市大岭山镇元岭村翠园街7巷20号102铺","call_center":"15916985301","distance":"2146.3km","average_price_tip":"人均20","comment_number":53,"lng":"113.854074","lat":"22.901119","__v":0,"created_at":"2018-04-05T05:08:44.533Z","discounts2":[{"info":"满20减18;满45减40;满60减53","icon_url":"http://p0.meituan.net/xianfu/f8bc8dffdbc805878aa3801a33f563cd1001.png","promotion_type":2},{"info":"折扣商品7.33折起","icon_url":"http://p1.meituan.net/xianfu/9c997ecce6150671b8459738a26f8bd9767.png","promotion_type":2},{"info":"新用户立减2元,首次使用银行卡支付最高再减3元","icon_url":"http://p0.meituan.net/xianfu/019d1bbb1310b1531e6af6172c9a5095581.png","promotion_type":2}]},{"_id":"5ac5b4383714cc2d644f4696","id":33,"name":"伏牛炸鸡汉堡","month_sales":173,"month_sales_tip":"月售173笔","wm_poi_score":1.6,"delivery_score":3.1,"quality_score":1.3,"pack_score":1.8,"food_score":0.7,"delivery_time_tip":"1525.4分钟","third_category":"中式简餐","pic_url":"http://p0.meituan.net/xianfu/55493399bb1c6e4884ff9456f92a391119693.jpg","shopping_time_start":"8:00","shopping_time_end":"24:00","min_price":10,"min_price_tip":"起送 ¥10","shipping_fee":0,"shipping_fee_tip":"配送 ¥0","bulletin":"理工专送,新旧男生宿舍下单都送到宿舍楼上。女生下楼领取。1点半到4点接受预订单。","address":"东莞市大岭山镇元岭村元岭综合市场1140号铺位","call_center":"15024098870","distance":"2146.2km","average_price_tip":"人均20","comment_number":50,"lng":"113.854364","lat":"22.902121","__v":0,"created_at":"2018-04-05T05:08:44.533Z","discounts2":[{"info":"满20减18;满45减40;满60减53","icon_url":"http://p0.meituan.net/xianfu/f8bc8dffdbc805878aa3801a33f563cd1001.png","promotion_type":2},{"info":"折扣商品7.33折起","icon_url":"http://p1.meituan.net/xianfu/9c997ecce6150671b8459738a26f8bd9767.png","promotion_type":2},{"info":"新用户立减2元,首次使用银行卡支付最高再减3元","icon_url":"http://p0.meituan.net/xianfu/019d1bbb1310b1531e6af6172c9a5095581.png","promotion_type":2}]},{"_id":"5ac5b7fb3714cc2d644f4756","id":35,"name":"潇湘粤语(东城万达店)","month_sales":28,"month_sales_tip":"月售28笔","wm_poi_score":2,"delivery_score":3.5,"quality_score":0.5,"pack_score":0.8,"food_score":1.6,"delivery_time_tip":"1521.1分钟","third_category":"中式简餐","pic_url":"http://p0.meituan.net/xianfu/4f5897d268ec95176d8afd4bf6e8a7252376.jpg","shopping_time_start":"8:00","shopping_time_end":"24:00","min_price":20,"min_price_tip":"起送 ¥20","shipping_fee":4,"shipping_fee_tip":"配送 ¥4","bulletin":"亲,记得点米饭哦!!\n 即日起:凡在本店下单送免费小吃一份\n               订单满200元送水果一份","address":"东城区万达广场室内步行街三层3016","call_center":"076987006660","distance":"2169.6km","average_price_tip":"人均20","comment_number":45,"lng":"113.780507","lat":"23.034935","__v":0,"created_at":"2018-04-05T05:08:44.533Z","discounts2":[{"info":"满20减18;满45减40;满60减53","icon_url":"http://p0.meituan.net/xianfu/f8bc8dffdbc805878aa3801a33f563cd1001.png","promotion_type":2},{"info":"折扣商品7.33折起","icon_url":"http://p1.meituan.net/xianfu/9c997ecce6150671b8459738a26f8bd9767.png","promotion_type":2},{"info":"新用户立减2元,首次使用银行卡支付最高再减3元","icon_url":"http://p0.meituan.net/xianfu/019d1bbb1310b1531e6af6172c9a5095581.png","promotion_type":2}]},{"_id":"5ac5ba2f3714cc2d644f47f1","id":36,"name":"麦当劳(东城万达店)","month_sales":32,"month_sales_tip":"月售32笔","wm_poi_score":2.8,"delivery_score":2.8,"quality_score":3.4,"pack_score":3.6,"food_score":0.3,"delivery_time_tip":"1520.1分钟","third_category":"中式简餐","pic_url":"http://p0.meituan.net/xianfu/851a8deb169f4f8aab16a7688932328f5634.jpg","shopping_time_start":"8:00","shopping_time_end":"24:00","min_price":20,"min_price_tip":"起送 ¥20","shipping_fee":3,"shipping_fee_tip":"配送 ¥3","bulletin":"欢迎下单","address":"东城区东纵大道万达广场2楼2027/2028号商铺","call_center":"0769-83785043","distance":"2164.0km","average_price_tip":"人均20","comment_number":41,"lng":"113.779576","lat":"23.035256","__v":0,"created_at":"2018-04-05T05:08:44.533Z","discounts2":[{"info":"满20减18;满45减40;满60减53","icon_url":"http://p0.meituan.net/xianfu/f8bc8dffdbc805878aa3801a33f563cd1001.png","promotion_type":2},{"info":"折扣商品7.33折起","icon_url":"http://p1.meituan.net/xianfu/9c997ecce6150671b8459738a26f8bd9767.png","promotion_type":2},{"info":"新用户立减2元,首次使用银行卡支付最高再减3元","icon_url":"http://p0.meituan.net/xianfu/019d1bbb1310b1531e6af6172c9a5095581.png","promotion_type":2}]}]
     */

    private int status;
    private String message;
    private List<DataBean> data;

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

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

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

    public static class DataBean {
        /**
         * _id : 5ac5af803714cc2d644f4615
         * id : 32
         * name : 麦当当的店
         * month_sales : 194
         * month_sales_tip : 月售194笔
         * wm_poi_score : 3
         * delivery_score : 2.1
         * quality_score : 3.7
         * pack_score : 4.1
         * food_score : 1.1
         * delivery_time_tip : 1525.9分钟
         * third_category : 中式简餐
         * pic_url : http://p0.meituan.net/xianfu/fdd295e7650587269e0f1d7c35ba180c114177.jpg
         * shopping_time_start : 8:00
         * shopping_time_end : 24:00
         * min_price : 10
         * min_price_tip : 起送 ¥10
         * shipping_fee : 0
         * shipping_fee_tip : 配送 ¥0
         * bulletin : 理工短号615592(原大学生粗粮坊)做你身边最快的外卖!
         * address : 东莞市大岭山镇元岭村翠园街7巷20号102铺
         * call_center : 15916985301
         * distance : 2146.3km
         * average_price_tip : 人均20
         * comment_number : 53
         * lng : 113.854074
         * lat : 22.901119
         * __v : 0
         * created_at : 2018-04-05T05:08:44.533Z
         * discounts2 : [{"info":"满20减18;满45减40;满60减53","icon_url":"http://p0.meituan.net/xianfu/f8bc8dffdbc805878aa3801a33f563cd1001.png","promotion_type":2},{"info":"折扣商品7.33折起","icon_url":"http://p1.meituan.net/xianfu/9c997ecce6150671b8459738a26f8bd9767.png","promotion_type":2},{"info":"新用户立减2元,首次使用银行卡支付最高再减3元","icon_url":"http://p0.meituan.net/xianfu/019d1bbb1310b1531e6af6172c9a5095581.png","promotion_type":2}]
         */

        private String _id;
        private int id;
        private String name;
        private int month_sales;
        private String month_sales_tip;
        private float wm_poi_score;
        private double delivery_score;
        private double quality_score;
        private double pack_score;
        private double food_score;
        private String delivery_time_tip;
        private String third_category;
        private String pic_url;
        private String shopping_time_start;
        private String shopping_time_end;
        private int min_price;
        private String min_price_tip;
        private int shipping_fee;
        private String shipping_fee_tip;
        private String bulletin;
        private String address;
        private String call_center;
        private String distance;
        private String average_price_tip;
        private int comment_number;
        private String lng;
        private String lat;
        private int __v;
        private String created_at;
        private List<Discounts2Bean> discounts2;

        public String get_id() {
            return _id;
        }

        public void set_id(String _id) {
            this._id = _id;
        }

        public int getId() {
            return id;
        }

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

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getMonth_sales() {
            return month_sales;
        }

        public void setMonth_sales(int month_sales) {
            this.month_sales = month_sales;
        }

        public String getMonth_sales_tip() {
            return month_sales_tip;
        }

        public void setMonth_sales_tip(String month_sales_tip) {
            this.month_sales_tip = month_sales_tip;
        }

        public float getWm_poi_score() {
            return wm_poi_score;
        }

        public void setWm_poi_score(float wm_poi_score) {
            this.wm_poi_score = wm_poi_score;
        }

        public double getDelivery_score() {
            return delivery_score;
        }

        public void setDelivery_score(double delivery_score) {
            this.delivery_score = delivery_score;
        }

        public double getQuality_score() {
            return quality_score;
        }

        public void setQuality_score(double quality_score) {
            this.quality_score = quality_score;
        }

        public double getPack_score() {
            return pack_score;
        }

        public void setPack_score(double pack_score) {
            this.pack_score = pack_score;
        }

        public double getFood_score() {
            return food_score;
        }

        public void setFood_score(double food_score) {
            this.food_score = food_score;
        }

        public String getDelivery_time_tip() {
            return delivery_time_tip;
        }

        public void setDelivery_time_tip(String delivery_time_tip) {
            this.delivery_time_tip = delivery_time_tip;
        }

        public String getThird_category() {
            return third_category;
        }

        public void setThird_category(String third_category) {
            this.third_category = third_category;
        }

        public String getPic_url() {
            return pic_url;
        }

        public void setPic_url(String pic_url) {
            this.pic_url = pic_url;
        }

        public String getShopping_time_start() {
            return shopping_time_start;
        }

        public void setShopping_time_start(String shopping_time_start) {
            this.shopping_time_start = shopping_time_start;
        }

        public String getShopping_time_end() {
            return shopping_time_end;
        }

        public void setShopping_time_end(String shopping_time_end) {
            this.shopping_time_end = shopping_time_end;
        }

        public int getMin_price() {
            return min_price;
        }

        public void setMin_price(int min_price) {
            this.min_price = min_price;
        }

        public String getMin_price_tip() {
            return min_price_tip;
        }

        public void setMin_price_tip(String min_price_tip) {
            this.min_price_tip = min_price_tip;
        }

        public int getShipping_fee() {
            return shipping_fee;
        }

        public void setShipping_fee(int shipping_fee) {
            this.shipping_fee = shipping_fee;
        }

        public String getShipping_fee_tip() {
            return shipping_fee_tip;
        }

        public void setShipping_fee_tip(String shipping_fee_tip) {
            this.shipping_fee_tip = shipping_fee_tip;
        }

        public String getBulletin() {
            return bulletin;
        }

        public void setBulletin(String bulletin) {
            this.bulletin = bulletin;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getCall_center() {
            return call_center;
        }

        public void setCall_center(String call_center) {
            this.call_center = call_center;
        }

        public String getDistance() {
            return distance;
        }

        public void setDistance(String distance) {
            this.distance = distance;
        }

        public String getAverage_price_tip() {
            return average_price_tip;
        }

        public void setAverage_price_tip(String average_price_tip) {
            this.average_price_tip = average_price_tip;
        }

        public int getComment_number() {
            return comment_number;
        }

        public void setComment_number(int comment_number) {
            this.comment_number = comment_number;
        }

        public String getLng() {
            return lng;
        }

        public void setLng(String lng) {
            this.lng = lng;
        }

        public String getLat() {
            return lat;
        }

        public void setLat(String lat) {
            this.lat = lat;
        }

        public int get__v() {
            return __v;
        }

        public void set__v(int __v) {
            this.__v = __v;
        }

        public String getCreated_at() {
            return created_at;
        }

        public void setCreated_at(String created_at) {
            this.created_at = created_at;
        }

        public List<Discounts2Bean> getDiscounts2() {
            return discounts2;
        }

        public void setDiscounts2(List<Discounts2Bean> discounts2) {
            this.discounts2 = discounts2;
        }

        public static class Discounts2Bean {
            /**
             * info : 满20减18;满45减40;满60减53
             * icon_url : http://p0.meituan.net/xianfu/f8bc8dffdbc805878aa3801a33f563cd1001.png
             * promotion_type : 2
             */

            private String info;
            private String icon_url;
            private int promotion_type;

            public String getInfo() {
                return info;
            }

            public void setInfo(String info) {
                this.info = info;
            }

            public String getIcon_url() {
                return icon_url;
            }

            public void setIcon_url(String icon_url) {
                this.icon_url = icon_url;
            }

            public int getPromotion_type() {
                return promotion_type;
            }

            public void setPromotion_type(int promotion_type) {
                this.promotion_type = promotion_type;
            }
        }
    }
}

ICallBack

public interface ICallBack {

    void success(Object obj);

    void failed(Exception e);
}

HttpUtils

public class HttpUtils {
    private static final HttpUtils ourInstance = new HttpUtils();
    private final OkHttpClient client;
    private static volatile HttpUtils instance;
    private Handler handler = new Handler();
    public static HttpUtils getInstance() {
        if (instance == null){
            synchronized (HttpUtils.class){
                if (null == instance){
                    instance = new HttpUtils();
                }
            }
        }
        return instance;
    }

    private HttpUtils() {
        client = new OkHttpClient();
    }
    public void get(String url, final ICallBack callBack, final Type type){
        Request request = new Request
                .Builder()
                .get()
                .url(url)
                .build();
        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, final IOException e) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        callBack.failed(e);
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String result = response.body().string();
                Gson gson = new Gson();
                final Object o = gson.fromJson(result, type);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        callBack.success(o);
                    }
                });
            }
        });
    }
}

HomeModel

public class HomeModel {

    public void getData(String url, ICallBack callBack, Type type){
        HttpUtils.getInstance().get(url, callBack, type);
    }

}

IView

public interface IView {

    void getCategory(List<JiuBean.DataBean> list);

    void getProduct(List<Product.DataBean> list);

    void failed(Exception e);
}

HomePresenter

public class HomePresenter {
    private IView iv;
    private HomeModel model;

    public void attach(IView iv) {
        this.iv = iv;
        model = new HomeModel();
    }
    public void getCategory() {

        Type type = new TypeToken<JiuBean>() {
        }.getType();

        model.getData("http://www.zhaoapi.cn/product/getCatagory", new ICallBack() {
            @Override
            public void success(Object obj) {
                JiuBean category = (JiuBean) obj;
                if (category != null) {
                    iv.getCategory(category.getData());
                }
            }

            @Override
            public void failed(Exception e) {
                iv.failed(e);
            }
        }, type);
    }
    public void getProduct(){
        String url = "http://www.wanandroid.com/tools/mockapi/6523/restaurants_offset_0_limit_4";
        Type type = new TypeToken<Product>() {
        }.getType();
        model.getData(url, new ICallBack() {
            @Override
            public void success(Object obj) {
                Product product = (Product) obj;
                if (product != null){
                    iv.getProduct(product.getData());
                }
            }

            @Override
            public void failed(Exception e) {
                iv.failed(e);
            }
        },type);
    }
}

JiuAdapter

public class JiuAdapter extends BaseAdapter {
    private Context context;
    private List<JiuBean.DataBean> list;

    public JiuAdapter(Context context, List<JiuBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @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 View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.img_item, null);
            viewHolder.imageView = convertView.findViewById(R.id.img);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        Glide.with(context).load(list.get(position).getIcon()).into(viewHolder.imageView);

        return convertView;
    }

    class ViewHolder {
        private ImageView imageView;
    }
}

ProuctAdapter

public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.ViewHolder> {
    private Context context;
    private List<Product.DataBean> list;

    public ProductAdapter(Context context, List<Product.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = View.inflate(context, R.layout.itme_layout, null);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Glide.with(context).load(list.get(position).getPic_url()).into(holder.imageView);
        holder.textView.setText(list.get(position).getName());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView imageView;
        private TextView textView;
        public ViewHolder(View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.image_view);
            textView = itemView.findViewById(R.id.text_view);
        }
    }
}

MainActivity

public class MainActivity extends AppCompatActivity implements IView {

    private GridView grid_view;
    private RecyclerView recy_view;
    private HomePresenter presenter;
    private List<Product.DataBean> productList;
    private List<JiuBean.DataBean> jiuList;
    private JiuAdapter jiuAdapter;
    private ProductAdapter productAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }

    private void initData() {
        //调用P层
        presenter = new HomePresenter();
        presenter.attach(this);
        presenter.getCategory();
        presenter.getProduct();

        productList = new ArrayList<>();
        jiuList = new ArrayList<>();

        jiuAdapter = new JiuAdapter(this,jiuList);
        productAdapter = new ProductAdapter(this, productList);

        grid_view.setAdapter(jiuAdapter);

        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        recy_view.setLayoutManager(layoutManager);

        recy_view.setAdapter(productAdapter);
    }

    private void initView() {
        grid_view = findViewById(R.id.grid_view);
        recy_view = findViewById(R.id.recy_view);
    }


    @Override
    public void getCategory(List<JiuBean.DataBean> list) {
        if (list != null){
            jiuList.clear();
            jiuList.addAll(list);
            jiuAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void getProduct(List<Product.DataBean> list) {
        if (list != null){
            productList.clear();
            productList.addAll(list);
            productAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void failed(Exception e) {
        Toast.makeText(this, "网络异常", Toast.LENGTH_SHORT).show();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}