//V层
public interface XqActivity { public void show(String str); public void showNews(GoodXiangBean goodXiangBean); }
//M层
public interface IXqModel { public void getShow(OnNetListener<GoodXiangBean> onNetListener, String pid); }
public class XqModel implements IXqModel { @Override public void getShow(final OnNetListener<GoodXiangBean> onNetListener, String pid) { ServerApi serverApi = RetrofitHelper.getServerApi(); serverApi.detail(pid) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber<GoodXiangBean>(){ @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(GoodXiangBean goodXiangBean) { onNetListener.onSuccess(goodXiangBean); } }); } }
//P层
public class XqPresenter { private XqActivity xqActivity; private IXqModel iXqModel; public XqPresenter(XqActivity xqActivity) { this.xqActivity = xqActivity; this.iXqModel=new XqModel(); } public void getData(String pid){ iXqModel.getShow(new OnNetListener<GoodXiangBean>() { @Override public void onSuccess(GoodXiangBean goodXiangBean) { xqActivity.showNews(goodXiangBean); } @Override public void onFailure(Exception e) { } },pid); } }
//主方法
public class Main2Activity extends AppCompatActivity implements View.OnClickListener,XqActivity { private SimpleDraweeView mDeSdv; private TextView mDeTv1; /** * ¥ */ private TextView mDePrice; /** * 评价 */ private TextView mDePj; /** * 购物车 */ private Button mShowCart; /** * 加入购物车 */ private Button mAddcar; private GoodXiangBean.DataBean data; private int uid; private XqPresenter xiangPresenter; private AddPresenter addPresenter; public TwoStatePreference allCheckbox; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); initView(); Intent intent = getIntent(); String pid = intent.getStringExtra("pid"); xiangPresenter = new XqPresenter(this); addPresenter = new AddPresenter(this); xiangPresenter.getData(pid); uid = MyApp.sp.getInt("uid", 0); } private void initView() { mDeSdv = (SimpleDraweeView) findViewById(R.id.de_sdv); mDeTv1 = (TextView) findViewById(R.id.de_tv1); mDePrice = (TextView) findViewById(R.id.de_price); mDePj = (TextView) findViewById(R.id.de_pj); mShowCart = (Button) findViewById(R.id.show_cart); mShowCart.setOnClickListener(this); mAddcar = (Button) findViewById(R.id.addcar); mAddcar.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { default: break; case R.id.show_cart: Intent intent = new Intent(Main2Activity.this, Main3Activity.class); startActivity(intent); break; case R.id.addcar: addPresenter.setAdd(uid+"71",+data.getPid()); break; } } @Override public void show(String str) { Toast.makeText(Main2Activity.this, str, Toast.LENGTH_SHORT).show(); } @Override public void showNews(GoodXiangBean goodXiangBean) { data = goodXiangBean.getData(); String images = this.data.getImages(); String[] split = images.split("\\|"); mDeSdv.setImageURI(split[0]); mDeTv1.setText(this.data.getTitle()); mDePrice.setText("¥" + this.data.getPrice()); } }//bean类public class GoodXiangBean { /** * 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; } } }//布局<?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" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp"> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/de_sdv" android:layout_width="match_parent" android:layout_height="200dp" app:placeholderImage="@mipmap/ic_launcher_round" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:orientation="vertical"> <TextView android:id="@+id/de_tv1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp" /> <TextView android:id="@+id/de_price" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="26dp" android:text="¥" android:textColor="#F23030" android:textSize="20sp" /> <TextView android:id="@+id/de_pj" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="评价" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentBottom="true" android:layout_weight="9" android:orientation="horizontal"> <Button android:id="@+id/show_cart" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="购物车" /> <Button android:id="@+id/addcar" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="加入购物车" /> </LinearLayout> </LinearLayout> </LinearLayout>
2676

被折叠的 条评论
为什么被折叠?



