商品详情

在适配器里面进行点击跳转

 final int pid = list.get(position).getPid();

            holder.img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(context, Shangpin.class);
                    intent.putExtra("pid",pid);
                    context.startActivity(intent);
                }
            });


跳转后的商品详情页面

public class Shangpin extends AppCompatActivity {

    private RecyclerView spRec;
    private List<SPBean.DataBean> list=new ArrayList<>();
    private TextView title;
    private ImageView img;
    private TextView subhead;
    private TextView price;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shangpin);

        img = (ImageView) findViewById(R.id.image_view);
        title = (TextView) findViewById(R.id.title_text);
        subhead = (TextView) findViewById(R.id.subhead_text);
        price = (TextView) findViewById(R.id.price_text);

        int pid = getIntent().getIntExtra("pid", 1);

        OkHttp3Util.doGet("https://www.zhaoapi.cn/product/getProductDetail?source=android&pid="+pid, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                final String json = response.body().string();
                Log.e("-----", "onResponse: "+json);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Gson gson=new Gson();
                        SPBean spBean = gson.fromJson(json, SPBean.class);
                        SPBean.DataBean data = spBean.getData();

                       String[] split = data.getImages().split("\\|");
                //        ImageLoader.getInstance().displayImage(split[0],img);
                      Glide.with(Shangpin.this).load(split[0]).into(img);
                        title.setText(data.getTitle());
                        subhead.setText(data.getSubhead());
                        price.setText(data.getPrice()+"");

                    }
                });

            }
        });


    }

    public void btn_Click(View view) {
        Toast.makeText(Shangpin.this,"已经成功添加到购物车",Toast.LENGTH_SHORT).show();
    }
}


布局

<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="zhuyuanyuan.bwei.com.sanzhoukao.XiangQing">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:id="@+id/linearLayout">

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_margin="5dp"
            android:src="@drawable/leftjiantou" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="商品"
            android:textSize="20dp"
            android:textColor="#000"
            android:layout_marginTop="15dp"
            android:layout_marginLeft="60dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="详情"
            android:textSize="15dp"
            android:textColor="#000"
            android:layout_marginTop="15dp"
            android:layout_marginLeft="20dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="评价"
            android:textSize="15dp"
            android:textColor="#000"
            android:layout_marginTop="15dp"
            android:layout_marginRight="60dp"
            android:layout_marginLeft="20dp"
            />

        <ImageView
            android:id="@+id/share"
            android:layout_width="25dp"
            android:layout_height="25dp"
            android:layout_margin="12dp"

            android:src="@drawable/share" />



    </LinearLayout>


    <ScrollView
        android:id="@+id/ll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="12">

        <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="vertical">


            <ImageView
                android:id="@+id/image_view"
                android:layout_width="260dp"
                android:layout_height="260dp"
                android:layout_marginTop="10dp"
                />

            <TextView
                android:id="@+id/title_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"

                android:textColor="#000"
                android:layout_marginTop="9dp"
                android:layout_marginLeft="5dp"
                android:textSize="16dp" />
            <TextView
                android:id="@+id/subhead_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="9dp"

                android:layout_marginLeft="5dp"
                android:textColor="#ff55"
                android:textSize="16dp" />

            <TextView
                android:id="@+id/price_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="9dp"
                android:layout_marginLeft="10dp"

                android:textColor="#ff55"
                android:textSize="25dp" />




        </LinearLayout>


    </ScrollView>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_weight="2"
        android:orientation="horizontal"
        android:gravity="center_vertical"
        >


        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"

            android:layout_weight="1"
            android:orientation="horizontal"
            >
            <LinearLayout
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="1"
                android:gravity="center"
                android:layout_marginLeft="10dp"
                android:orientation="vertical"

                >
                <ImageView
                    android:layout_width="22dp"
                    android:layout_height="22dp"
                    android:layout_marginTop="5dp"
                    android:gravity="center_horizontal"
                    android:src="@drawable/lingdang"
                    />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="5dp"
                    android:gravity="center_horizontal"
                    android:text="联系卖家"
                    android:textSize="10dp"
                    />


            </LinearLayout>



            <LinearLayout
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_weight="1"

                >
                <ImageView
                    android:layout_width="22dp"
                    android:layout_height="22dp"
                    android:layout_marginTop="5dp"
                    android:src="@drawable/dianpu"
                    />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="5dp"
                    android:gravity="center_horizontal"
                    android:text="店铺"
                    android:textSize="10dp"
                    />




            </LinearLayout>
            <LinearLayout
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:gravity="center"
                android:orientation="vertical"
                android:layout_weight="1"

                >
                <CheckBox
                    android:id="@+id/guanzhi"
                    android:layout_width="22dp"
                    android:layout_height="22dp"
                    android:layout_marginTop="5dp"
                    android:button="@null"
                    android:background="@drawable/normalheart"
                    />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="5dp"
                    android:text="关注"
                    android:gravity="center_horizontal"
                    android:textSize="10dp"
                    />


            </LinearLayout>
            <LinearLayout
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:orientation="vertical"
                android:gravity="center"
                android:layout_weight="1"

                >
                <ImageView
                    android:layout_width="22dp"
                    android:layout_height="22dp"
                    android:layout_marginTop="5dp"
                    android:background="@drawable/shopcar"
                    />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="5dp"
                    android:gravity="center_horizontal"
                    android:text="购物车"
                    android:textSize="10dp"
                    />


            </LinearLayout>



        </LinearLayout>

        <Button
            android:id="@+id/btn_fan3"
            android:onClick="btn_Click"
            android:layout_width="90dp"
            android:layout_weight="0.1"
            android:background="#ff55"
            android:layout_height="match_parent"
            android:textColor="#fff"
            android:text="加入购物车"
            />


    </LinearLayout>

</LinearLayout>

封装的SPBean类

package zhuyuanyuan.bwei.com.jingdong.model.bean;

/**
 * Created by dell on 2018/1/10.
 */

public class SPBean {


    /**
     * msg :
     * seller : {"description":"我是商家22","icon":"http://120.27.23.105/images/icon.png","name":"商家22","productNums":999,"score":5,"sellerid":22}
     * code : 0
     * data : {"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":1,"pid":78,"price":999,"pscid":40,"salenum":656,"sellerid":22,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}
     */

    private String msg;
    private SellerBean seller;
    private String code;
    private DataBean data;

    public String getMsg() {
        return msg;
    }

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

    public SellerBean getSeller() {
        return seller;
    }

    public void setSeller(SellerBean seller) {
        this.seller = seller;
    }

    public String getCode() {
        return code;
    }

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

    public DataBean getData() {
        return data;
    }

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

    public static class SellerBean {
        /**
         * description : 我是商家22
         * icon : http://120.27.23.105/images/icon.png
         * name : 商家22
         * productNums : 999
         * score : 5.0
         * sellerid : 22
         */

        private String description;
        private String icon;
        private String name;
        private int productNums;
        private double score;
        private int sellerid;

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public String getIcon() {
            return icon;
        }

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

        public String getName() {
            return name;
        }

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

        public int getProductNums() {
            return productNums;
        }

        public void setProductNums(int productNums) {
            this.productNums = productNums;
        }

        public double getScore() {
            return score;
        }

        public void setScore(double score) {
            this.score = score;
        }

        public int getSellerid() {
            return sellerid;
        }

        public void setSellerid(int sellerid) {
            this.sellerid = sellerid;
        }
    }

    public static class DataBean {
        /**
         * bargainPrice : 11800.0
         * createtime : 2017-10-14T21:38:26
         * detailUrl : https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1
         * images : https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg
         * itemtype : 1
         * pid : 78
         * price : 999.0
         * pscid : 40
         * salenum : 656
         * sellerid : 22
         * subhead : 购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)
         * title : 全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G
         */

        private double bargainPrice;
        private String createtime;
        private String detailUrl;
        private String images;
        private int itemtype;
        private int pid;
        private double price;
        private int pscid;
        private int salenum;
        private int sellerid;
        private String subhead;
        private String title;

        public double getBargainPrice() {
            return bargainPrice;
        }

        public void setBargainPrice(double bargainPrice) {
            this.bargainPrice = bargainPrice;
        }

        public String getCreatetime() {
            return createtime;
        }

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

        public String getDetailUrl() {
            return detailUrl;
        }

        public void setDetailUrl(String detailUrl) {
            this.detailUrl = detailUrl;
        }

        public String getImages() {
            return images;
        }

        public void setImages(String images) {
            this.images = images;
        }

        public int getItemtype() {
            return itemtype;
        }

        public void setItemtype(int itemtype) {
            this.itemtype = itemtype;
        }

        public int getPid() {
            return pid;
        }

        public void setPid(int pid) {
            this.pid = pid;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }

        public int getPscid() {
            return pscid;
        }

        public void setPscid(int pscid) {
            this.pscid = pscid;
        }

        public int getSalenum() {
            return salenum;
        }

        public void setSalenum(int salenum) {
            this.salenum = salenum;
        }

        public int getSellerid() {
            return sellerid;
        }

        public void setSellerid(int sellerid) {
            this.sellerid = sellerid;
        }

        public String getSubhead() {
            return subhead;
        }

        public void setSubhead(String subhead) {
            this.subhead = subhead;
        }

        public String getTitle() {
            return title;
        }

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



猜你喜欢

转载自blog.csdn.net/Zyy_921/article/details/79096123