北京東商品の詳細ページを模仿する(ショッピングカートに協力して使用する)
12980 ワード
:mvp要求OKを使ってネットワークを要求します.ここでmvpを展示して簡単に使用します.
一.商品詳細ページのactivityコード
三详情页Viewpager适配器
一.商品詳細ページのactivityコード
package com.bwie.skn.moni.recyclerDetails;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.bwie.skn.moni.R;
import com.bwie.skn.moni.adapter.DetailsAdapter;
import com.bwie.skn.moni.bean.RecyclerDetailsBean;
import com.bwie.skn.moni.shoppingCar.ShoppingCartActivity;
import java.util.ArrayList;
public class RecyclerDetailsActivity extends AppCompatActivity implements IRecyclerDetailsPresenter,IAddShopCarPresenter{
private int pid = 71;
private RecyclerDetailsPresenter recyclerDetailsPresenter;
private ListView listView;
private RecyclerDetailsBean.DataBean data;
private TextView title;
private TextView price;
private String urlImg;
private String[] split;
private String urlTitle;
private double urlPrice;
private ArrayList lists = new ArrayList();
private ViewPager viewPager;
private DetailsAdapter adapter;
private Button join;
private int pids;
private AddShopCarPresenter addShopCarPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
viewPager = (ViewPager) findViewById(R.id.viewPager);
join = (Button) findViewById(R.id.join);
title = (TextView) findViewById(R.id.title);
price = (TextView) findViewById(R.id.price);
//Intent intent = getIntent();
//pid = intent.getIntExtra("pid", this.pid);
recyclerDetailsPresenter = new RecyclerDetailsPresenter(this);
recyclerDetailsPresenter.receive(pid + "");
addShopCarPresenter = new AddShopCarPresenter(this);
}
@Override
public void onSuccess(RecyclerDetailsBean rdBean) {
/**
* ,
*/
data = rdBean.getData();
pids = data.getPid();
urlImg = data.getImages();
split = urlImg.split("\\|");
urlTitle = data.getTitle();
urlPrice = data.getPrice();
title.setText(urlTitle);
price.setText(urlPrice + "");
/**
*
*
*/
adapter = new DetailsAdapter(RecyclerDetailsActivity.this, split);
viewPager.setAdapter(adapter);
/**
*
*/
join.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
/*Toast.makeText(RecyclerDetailsActivity.this, ImageLoaderApp.sql.getInt("id", 0)+"", Toast.LENGTH_SHORT).show();*/
//
addShopCarPresenter.receive("android", 3381+"", pids + "");
}
});
}
@Override
public void onSuccess(String msg) {
Toast.makeText(RecyclerDetailsActivity.this, msg, Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed() {
}
/**
*
* @param view
*/
public void shopcar(View view){
Intent intent = new Intent(RecyclerDetailsActivity.this, ShoppingCartActivity.class);
startActivity(intent);
}
}
二.ホームページのレイアウト
三详情页Viewpager适配器
package com.bwie.skn.moni.adapter;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bwie.skn.moni.R;
/**
* author:Created by ZhangPengFei on 2017/12/18.
*
*/
public class DetailsAdapter extends PagerAdapter {
private Context context;
private String[] split;
public DetailsAdapter(Context context, String[] split) {
this.context = context;
this.split = split;
}
@Override
public int getCount() {
return Integer.MAX_VALUE;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = View.inflate(context, R.layout.layout_detailviewpager, null);
ImageView img = view.findViewById(R.id.img);
Glide.with(context).load(split[position%split.length]).into(img);
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
}
四.商品詳細ページのBeanページpackage com.bwie.skn.moni.bean;
/**
* author:Created by ZhangPengFei on 2017/12/17.
*/
public class RecyclerDetailsBean {
/**
* msg :
* seller : {"description":" 17","icon":"http://120.27.23.105/images/icon.png","name":" 17","productNums":999,"score":5,"sellerid":17}
* code : 0
* data : {"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","itemtype":1,"pid":1,"price":118,"pscid":1,"salenum":0,"sellerid":17,"subhead":" , , , , , , ","title":" 655g"}
*/
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 : 17
* icon : http://120.27.23.105/images/icon.png
* name : 17
* productNums : 999
* score : 5.0
* sellerid : 17
*/
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 : 111.99
* createtime : 2017-10-14T21:39:05
* detailUrl : https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends
* images : https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg
* itemtype : 1
* pid : 1
* price : 118.0
* pscid : 1
* salenum : 0
* sellerid : 17
* subhead : , , , , , ,
* title : 655g
*/
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;
}
}
}
五.