//导包
implementation 'com.jcodecraeer:xrecyclerview:1.3.2'
implementation 'com.squareup.okhttp3:okhttp:3.2.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
implementation 'com.google.code.gson:gson:2.6.2'
implementation 'com.github.bumptech.glide:glide:4.7.1'
//MainActivity.xml
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="@null"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/search_back"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:src="@drawable/ic_loading_rotate"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_toLeftOf="@+id/result_search"
android:layout_toRightOf="@+id/search_back"
android:focusable="true"
android:focusableInTouchMode="true"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/relation_search"
android:layout_centerVertical="true"
android:layout_marginLeft="9dp"
android:src="@drawable/loading_01"
/>
<View
android:layout_width="0.5dp"
android:layout_height="20dp"
android:id="@+id/search_line"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/relation_search"
android:background="#fff"></View>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/search_input_search"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/search_line"
android:background="@null"
android:hint="请输入关键词搜索"
android:textColor="@color/colorPrimaryDark"
android:textSize="14sp"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/result_search"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:textSize="14sp"
android:text="搜索"
/>
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:text="热搜"
android:textSize="20sp"
/>
<com.bwie.yuekao.view.CustomView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/search_flowlayout"
android:background="#fff"
android:paddingTop="10dp"
></com.bwie.yuekao.view.CustomView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="清空历史记录"
android:id="@+id/search_clear"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/search_list"
></ListView>
<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"
tools:context=".MainActivity"
>
<Button
android:onClick="add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="添加购物车!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Button
android:onClick="search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="查询购物车!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</LinearLayout>
</LinearLayout>
//MainActivity
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.bwie.yuekao.view.CustomView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
String[] name ={"手机","电脑","玩具","手机","电脑","苹果手机", "笔记本电脑", "电饭煲 ", "腊肉",
"特产", "剃须刀", "宝宝", "康佳", "特产", "剃须刀", "宝宝", "康佳"};
private ImageView mSearchBack;
private ImageView mRelationSearch;
private View mSearchLine;
/**
* 请输入关键词搜索
*/
private EditText mSearchInputSearch;
/**
* 搜索
*/
private TextView mResultSearch;
private CustomView mSearchFlowlayout;
/**
* 清空记录
*/
private Button mSearchClear;
private ListView mSearchList;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSearchBack = (ImageView) findViewById(R.id.search_back);
mRelationSearch = (ImageView) findViewById(R.id.relation_search);
mSearchLine = (View) findViewById(R.id.search_line);
mSearchInputSearch = (EditText) findViewById(R.id.search_input_search);
mResultSearch = (TextView) findViewById(R.id.result_search);
mSearchFlowlayout = (CustomView) findViewById(R.id.search_flowlayout);
mSearchClear = (Button) findViewById(R.id.search_clear);
mSearchClear.setOnClickListener(this);
mSearchList = (ListView) findViewById(R.id.search_list);
//设置默认显示
for (int i = 0; i < name.length; i++) {
textView = new TextView(this);
textView.setText(name[i]);
//设置内边距
textView.setPadding(5,5,5,5);
textView.setTextSize(20);
//设置颜色
textView.setTextColor(Color.RED);
//添加数据
mSearchFlowlayout.addView(textView);
}
//点击搜索添加
mResultSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String s = mSearchInputSearch.getText().toString();
textView = new TextView(MainActivity.this);
textView.setPadding(5,5,5,5);
textView.setTextSize(20);
textView.setText(s);
mSearchFlowlayout.addView(textView);
}
});
//mSearchFlowlayout.invalidate(); 刷新UI布局
// mSearchFlowlayout.removeAllViews(); 删除所有
//mSearchFlowlayout.removeView(); 删除单个子控件
}
public void add(View view) {
}
//查询购物车
public void search(View view) {
startActivity(new Intent(this,CartActivity.class));
}
@Override
public void onClick(View v) {
}
}
//CartActivy_cart.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="wrap_content"
tools:context=".CartActivity">
<com.jcodecraeer.xrecyclerview.XRecyclerView
android:id="@+id/cartGV"
android:layout_above="@+id/cart_bottom_layout"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:id="@+id/cart_bottom_layout"
android:padding="5dp"
android:background="@android:color/darker_gray"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:layout_centerVertical="true"
android:id="@+id/allCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/totalpriceTv"
android:textColor="#ffffff"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/allCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="总价:"/>
<Button
android:id="@+id/buy"
android:onClick="buy"
android:layout_alignParentRight="true"
android:text="去结算"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</RelativeLayout>
//CartVativity
package com.bwie.yuekao;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
import com.bwie.yuekao.adapter.CartAdapter;
import com.bwie.yuekao.bean.CartBean;
import com.bwie.yuekao.common.Contonts;
import com.bwie.yuekao.presenter.Cartpresenter;
import com.bwie.yuekao.view.IcartView;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import java.util.HashMap;
import java.util.List;
public class CartActivity extends AppCompatActivity implements IcartView{
private XRecyclerView xRecyclerView;
private CheckBox allCheckbox;
private TextView totalPriceTv;
private int page=1;
private Cartpresenter cartpresenter;
private List<CartBean.DataBean> list;
private CartAdapter cartAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart);
initView();
initData();
}
private void initData() {
loadData();
}
private void loadData() {
HashMap<String,String> params = new HashMap<>();
params.put("uid","71");
params.put("page",page+"");
cartpresenter = new Cartpresenter(this);
cartpresenter.getCarts(params, Contonts.GETCARTS);
}
//初始化控件
private void initView() {
xRecyclerView = findViewById(R.id.cartGV);
allCheckbox = findViewById(R.id.allCheckbox);
totalPriceTv = findViewById(R.id.totalpriceTv);
xRecyclerView.setLayoutManager(new LinearLayoutManager(this));
xRecyclerView.setLoadingMoreEnabled(true);
xRecyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
@Override
public void onRefresh() {
page=1;
loadData();
}
@Override
public void onLoadMore() {
page++;
loadData();
}
});
allCheckbox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (allCheckbox.isChecked()){
if (list !=null && list.size()>0){
for (int i =0;i<list.size();i++){
list.get(i).setSelected(true);
for (int i1=0;i1<list.get(i).getList().size();i1++){
list.get(i).getList().get(i1).setSelected(true);
}
}
}
}else{
if (list!=null && list.size() >0){
for (int i=0;i<list.size();i++){
list.get(i).setSelected(false);
for (int i1=0;i1<list.get(i).getList().size();i1++){
list.get(i).getList().get(i1).setSelected(false);
}
}
}
}
cartAdapter.notifyDataSetChanged();
}
});
}
public void buy(View view) {
}
@Override
public void success(CartBean cartBean) {
if (cartBean!=null && cartBean.getData()!=null){
list = cartBean.getData();
Log.i("bbbbbb",list+"");
cartAdapter = new CartAdapter(CartActivity.this, list);
xRecyclerView.setLayoutManager(new LinearLayoutManager(CartActivity.this));
xRecyclerView.setAdapter(cartAdapter);
xRecyclerView.refreshComplete();
}
}
@Override
public void error(String msg) {
}
}
//CartAdapter
package com.bwie.yuekao.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import com.bwie.yuekao.R;
import com.bwie.yuekao.bean.CartBean;
import java.util.List;
public class CartAdapter extends RecyclerView.Adapter<CartAdapter.CartViewHolder> {
private Context mcontext;
private List<CartBean.DataBean> cartlist;
private ProductAdapter productAdapter;
public CartAdapter(Context mcontext, List<CartBean.DataBean> cartlist) {
this.mcontext = mcontext;
this.cartlist = cartlist;
}
@NonNull
@Override
public CartViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(mcontext).inflate(R.layout.cart_bottom_layout, parent, false);
CartViewHolder viewHolder = new CartViewHolder(itemView);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull final CartViewHolder holder, int position) {
final CartBean.DataBean bean = cartlist.get(position);
holder.nameTv.setText(bean.getSellerName());
holder.productXRV.setLayoutManager(new LinearLayoutManager(mcontext));
productAdapter = new ProductAdapter(mcontext, bean.getList());
holder.productXRV.setAdapter(productAdapter);
holder.checkBox.setChecked(bean.isSelected());
holder.checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (holder.checkBox.isChecked()){
bean.setSelected(true);
for (int i=0;i<bean.getList().size();i++){
bean.getList().get(i).setSelected(true);
}
}else {
bean.setSelected(false);
for (int i = 0;i<bean.getList().size();i++){
bean.getList().get(i).setSelected(false);
}
}
notifyDataSetChanged();
}
});
}
@Override
public int getItemCount() {
return cartlist.size();
}
public class CartViewHolder extends RecyclerView.ViewHolder {
private final CheckBox checkBox;
private final TextView nameTv;
private final RecyclerView productXRV;
public CartViewHolder(View itemView) {
super(itemView);
checkBox = itemView.findViewById(R.id.sellerCheckbox);
nameTv = itemView.findViewById(R.id.sellerNameTv);
productXRV = itemView.findViewById(R.id.productXRV);
}
}
}
//productAdapter
package com.bwie.yuekao.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bwie.yuekao.R;
import com.bwie.yuekao.bean.CartBean;
import com.bwie.yuekao.wight.MyJIaJianView;
import java.util.List;
public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.CartViewHolder> {
private Context mContext;
private List<CartBean.DataBean.ListBean> listBeanList;
public ProductAdapter(Context mContext, List<CartBean.DataBean.ListBean> listBeanList) {
this.mContext = mContext;
this.listBeanList = listBeanList;
}
@NonNull
@Override
public ProductAdapter.CartViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(mContext).inflate(R.layout.product_item_layout, parent, false);
CartViewHolder cartViewHolder = new CartViewHolder(itemView);
return cartViewHolder;
}
@Override
public void onBindViewHolder(@NonNull ProductAdapter.CartViewHolder holder, int position) {
CartBean.DataBean.ListBean bean = listBeanList.get(position);
holder.priceTv.setText("优惠价:¥" + bean.getBargainPrice());
holder.titleTv.setText(bean.getTitle());
holder.checkBox.setChecked(bean.isSelected());
String [] imgs =bean.getImages().split("\\|");
if (imgs!=null && imgs.length>0){
Glide.with(mContext).load(imgs[0]).into(holder.productTv);
}else{
}
}
@Override
public int getItemCount() {
return listBeanList.size();
}
public class CartViewHolder extends RecyclerView.ViewHolder {
private final CheckBox checkBox;
private final TextView titleTv;
private final TextView priceTv;
private final MyJIaJianView myJIaJianView;
private final ImageView productTv;
public CartViewHolder(View itemView) {
super(itemView);
checkBox = itemView.findViewById(R.id.productCheckbox);
titleTv = itemView.findViewById(R.id.title);
priceTv = itemView.findViewById(R.id.price);
productTv = itemView.findViewById(R.id.product_icon);
myJIaJianView = itemView.findViewById(R.id.jiajianqi);
}
}
}
//CustomView
package com.bwie.yuekao.view;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
public class CustomView extends ViewGroup {
private int mleftMargin=20;
private int mtopMargin=20;
public CustomView(Context context) {
this(context,null);
}
public CustomView(Context context, AttributeSet attrs) {
this(context,attrs,0);
}
public CustomView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
measureChildren(widthMeasureSpec,heightMeasureSpec);
int leftMargin =mleftMargin;
int topMarigin =mtopMargin;
int viewHeight =0;
int viewWidth =0;
int sizeWidth = MeasureSpec.getSize(widthMeasureSpec);
int modeWidth = MeasureSpec.getMode(widthMeasureSpec);
int sizeHeight = MeasureSpec.getSize(heightMeasureSpec);
int modeHeight = MeasureSpec.getMode(heightMeasureSpec);
switch (modeHeight){
case MeasureSpec.AT_MOST:
int measuredHeight=0;
for (int j = 0; j < getChildCount(); j++) {
int measuredWidth = getChildAt(j).getMeasuredWidth();
measuredHeight = getChildAt(j).getMeasuredHeight();
if (leftMargin+measuredWidth+mleftMargin>getWidth()){
leftMargin=mleftMargin;
topMarigin+=measuredHeight+mtopMargin;
}
leftMargin+=measuredWidth+mleftMargin;
}
topMarigin+=measuredHeight+mtopMargin;
break;
}
setMeasuredDimension(sizeWidth,topMarigin);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int leftMargin = mleftMargin;
int topMargin = mtopMargin;
for (int j = 0; j < getChildCount(); j++) {
int measuredWidth = getChildAt(j).getMeasuredWidth();
int measuredHeight = getChildAt(j).getMeasuredHeight();
if (leftMargin+measuredWidth+mleftMargin>getWidth()){
leftMargin=mleftMargin;
topMargin+=measuredHeight+mtopMargin;
getChildAt(j).layout(leftMargin,topMargin,leftMargin+measuredWidth,topMargin+measuredHeight);
}else {
getChildAt(j).layout(leftMargin,topMargin,leftMargin+measuredWidth,topMargin+measuredHeight);
}
leftMargin+=measuredWidth+mleftMargin;
}
}
}
//View_IcartView
public interface IcartView {
void success(CartBean cartBean);
void error(String msg);
}
//Cartpresenter
package com.bwie.yuekao.presenter;
import com.bwie.yuekao.bean.CartBean;
import com.bwie.yuekao.model.CartModel;
import com.bwie.yuekao.view.IcartView;
import java.util.HashMap;
public class Cartpresenter {
private IcartView icartView;
private CartModel cartModel;
public Cartpresenter(IcartView icartView) {
cartModel = new CartModel();
attachView(icartView);
}
private void attachView(IcartView icartView) {
this.icartView=icartView;
}
public void getCarts(HashMap<String,String> params,String url){
cartModel.getCarts(params, url, new CartModel.CartCallback() {
@Override
public void success(CartBean cartBean) {
if (icartView!=null){
icartView.success(cartBean);
}
}
@Override
public void error(String msg) {
if (icartView!=null){
icartView.error(msg);
}
}
});
}
public void detachView(){
this.icartView =null;
}
}
//Model-CartModel
package com.bwie.yuekao.model;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import com.bwie.yuekao.bean.CartBean;
import com.bwie.yuekao.utils.OkHttputils;
import com.bwie.yuekao.utils.RequestCallback;
import com.google.gson.Gson;
import java.io.IOException;
import java.util.HashMap;
import okhttp3.Call;
import okhttp3.Response;
public class CartModel {
Handler handler =new Handler();
public void getCarts(HashMap<String,String> params,String url ,final CartCallback cartcallback ){
OkHttputils.getInstance().postData(url, params, new RequestCallback() {
@Override
public void failure(Call call, IOException e) {
if (cartcallback != null){
cartcallback.error("网络异常,请稍后再试");
}
}
@Override
public void onResponse(Call call, Response response) {
try {
String jsonResult = response.body().string();
Log.i("qqq", jsonResult);
if (!TextUtils.isEmpty(jsonResult)){
parsetResult(jsonResult,cartcallback);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private void parsetResult(String jsonResult, final CartCallback cartcallback) {
final CartBean cartBean = new Gson().fromJson(jsonResult, CartBean.class);
if (cartcallback!=null && cartBean!=null){
handler.post(new Runnable() {
@Override
public void run() {
cartcallback.success(cartBean);
}
});
}
Log.i("ssss",cartBean.toString());
}
});
}
public interface CartCallback{
void success(CartBean cartBean);
void error(String msg);
}
}
//bean_Cartbean
package com.bwie.yuekao.bean;
import java.util.List;
public class CartBean {
/**
* msg : 请求成功
* code : 0
* data : [{"list":[{"bargainPrice":11800,"createtime":"2017-10-10T17:33:37","detailUrl":"https://item.m.jd.com/product/4338107.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg","num":2,"pid":57,"price":5199,"pscid":40,"selected":0,"sellerid":1,"subhead":"【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统","title":"小米(MI)Air 13.3英寸全金属轻薄笔记本(i5-7200U 8G 256G PCle SSD MX150 2G独显 FHD 指纹识别 Win10)银\r\n"},{"bargainPrice":99,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg","num":2,"pid":45,"price":2999,"pscid":39,"selected":0,"sellerid":1,"subhead":"高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽!","title":"一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机"}],"sellerName":"商家1","sellerid":"1"},{"list":[{"bargainPrice":6666,"createtime":"2017-10-10T16:01:31","detailUrl":"https://item.m.jd.com/product/5089273.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8284/363/1326459580/71585/6d3e8013/59b857f2N6ca75622.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9346/182/1406837243/282106/68af5b54/59b8480aNe8af7f5c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8434/54/1359766007/56140/579509d9/59b85801Nfea207db.jpg!q70.jpg","num":1,"pid":46,"price":234,"pscid":39,"selected":0,"sellerid":2,"subhead":"【iPhone新品上市】新一代iPhone,让智能看起来更不一样","title":"Apple iPhone 8 Plus (A1864) 64GB 金色 移动联通电信4G手机"}],"sellerName":"商家2","sellerid":"2"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:48:08","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","num":1,"pid":65,"price":12000,"pscid":40,"selected":0,"sellerid":9,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家9","sellerid":"9"},{"list":[{"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","num":1,"pid":66,"price":13000,"pscid":40,"selected":0,"sellerid":10,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家10","sellerid":"10"},{"list":[{"bargainPrice":159,"createtime":"2017-10-14T21:49:15","detailUrl":"https://item.m.jd.com/product/5061723.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8716/197/1271594444/173291/2f40bb4f/59b743bcN8509428e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8347/264/1286771527/92188/5cf5ec04/59b7420fN65378e9e.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7363/165/3000956253/190883/179a372/59b743bfNd0c79d93.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7399/112/2935531768/183594/b77c7d4a/59b7441aNc3d40133.jpg!q70.jpg","num":1,"pid":100,"price":2200,"pscid":112,"selected":0,"sellerid":11,"subhead":"针织针织闪闪闪亮你的眼","title":"维迩旎 2017秋冬新款长袖针织连衣裙韩版气质中长款名媛包臀A字裙 zx179709 黑色 XL"},{"bargainPrice":22.9,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":2,"pid":34,"price":9,"pscid":2,"selected":0,"sellerid":11,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}],"sellerName":"商家11","sellerid":"11"},{"list":[{"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","num":1,"pid":72,"price":33999,"pscid":40,"selected":0,"sellerid":16,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":111.99,"createtime":"2017-10-14T21:38:26","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","num":1,"pid":23,"price":188,"pscid":1,"selected":0,"sellerid":16,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家16","sellerid":"16"},{"list":[{"bargainPrice":22.9,"createtime":"2017-10-03T23:53:28","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":1,"pid":40,"price":345,"pscid":2,"selected":0,"sellerid":17,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"},{"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","num":52,"pid":1,"price":118,"pscid":1,"selected":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家17","sellerid":"17"},{"list":[{"bargainPrice":22.9,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":1,"pid":41,"price":456,"pscid":2,"selected":0,"sellerid":18,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"},{"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","num":3,"pid":2,"price":299,"pscid":1,"selected":0,"sellerid":18,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家18","sellerid":"18"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-03T23:53:28","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","num":4,"pid":3,"price":198,"pscid":1,"selected":0,"sellerid":19,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"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","num":9,"pid":75,"price":36999,"pscid":40,"selected":0,"sellerid":19,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家19","sellerid":"19"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-03T23:53:28","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","num":2,"pid":76,"price":37999.99,"pscid":40,"selected":1,"sellerid":20,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家20","sellerid":"20"},{"list":[{"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","num":36,"pid":5,"price":88.99,"pscid":1,"selected":1,"sellerid":21,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家21","sellerid":"21"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-03T23:53:28","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","num":23,"pid":6,"price":7.99,"pscid":1,"selected":0,"sellerid":22,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家22","sellerid":"22"}]
*/
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 {
/**
* list : [{"bargainPrice":11800,"createtime":"2017-10-10T17:33:37","detailUrl":"https://item.m.jd.com/product/4338107.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg","num":2,"pid":57,"price":5199,"pscid":40,"selected":0,"sellerid":1,"subhead":"【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统","title":"小米(MI)Air 13.3英寸全金属轻薄笔记本(i5-7200U 8G 256G PCle SSD MX150 2G独显 FHD 指纹识别 Win10)银\r\n"},{"bargainPrice":99,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg","num":2,"pid":45,"price":2999,"pscid":39,"selected":0,"sellerid":1,"subhead":"高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽!","title":"一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机"}]
* sellerName : 商家1
* sellerid : 1
*/
private boolean isSelected=false;
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean selected) {
isSelected = selected;
}
private String sellerName;
private String sellerid;
private List<ListBean> list;
public String getSellerName() {
return sellerName;
}
public void setSellerName(String sellerName) {
this.sellerName = sellerName;
}
public String getSellerid() {
return sellerid;
}
public void setSellerid(String sellerid) {
this.sellerid = sellerid;
}
public List<ListBean> getList() {
return list;
}
public void setList(List<ListBean> list) {
this.list = list;
}
public static class ListBean {
/**
* bargainPrice : 11800
* createtime : 2017-10-10T17:33:37
* detailUrl : https://item.m.jd.com/product/4338107.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends
* images : https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg
* num : 2
* pid : 57
* price : 5199
* pscid : 40
* selected : 0
* sellerid : 1
* subhead : 【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统
* title : 小米(MI)Air 13.3英寸全金属轻薄笔记本(i5-7200U 8G 256G PCle SSD MX150 2G独显 FHD 指纹识别 Win10)银
*/
private boolean isSelected=false;
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean selected) {
isSelected = selected;
}
private double bargainPrice;
private String createtime;
private String detailUrl;
private String images;
private int num;
private int pid;
private double price;
private int pscid;
private int selected;
private int sellerid;
private String subhead;
private String title;
public double getBargainPrice() {
return bargainPrice;
}
public void setBargainPrice(int 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 getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public double getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getPscid() {
return pscid;
}
public void setPscid(int pscid) {
this.pscid = pscid;
}
public int getSelected() {
return selected;
}
public void setSelected(int selected) {
this.selected = selected;
}
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;
}
}
}
}
//weight_MyJIaJianView
package com.bwie.yuekao.wight;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.bwie.yuekao.R;
public class MyJIaJianView extends LinearLayout {
private TextView jiantv;
private TextView jiatv;
private EditText numEt;
private int num =1;
private int nul;
public MyJIaJianView(Context context) {
this(context,null);
}
public MyJIaJianView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs,0);
}
public MyJIaJianView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
View view = LayoutInflater.from(context).inflate(R.layout.jia_jian_layout,this,true);
jiantv = view.findViewById(R.id.jian);
jiatv = view.findViewById(R.id.jia);
numEt = view.findViewById(R.id.num);
numEt.setText(num+"");
jiantv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
num--;
if (num<=0){
Toast.makeText(getContext(), "数量不能小于1", Toast.LENGTH_SHORT).show();
num = 1;
}
numEt.setText(num+"");
if (jiaJianListener!=null){
jiaJianListener.getNum(num);
}
}
});
jiatv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
num++;
numEt.setText(num+"");
if (jiaJianListener!=null){
jiaJianListener.getNum(num);
}
}
});
}
public void setNumEt(int n){
numEt.setText(n+"");
num = Integer.parseInt(numEt.getText().toString());
}
private JiaJianListener jiaJianListener;
public void setJiaJianListener(JiaJianListener jiaJianListener){
this.jiaJianListener =jiaJianListener;
}
public interface JiaJianListener{
void getNum(int num);
}
}
//utils_OkHttputils
package com.bwie.yuekao.utils;
import android.util.Log;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
public class OkHttputils {
private static OkHttputils okHttputils;
private static OkHttpClient okhttpClient;
private OkHttputils(){
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
okhttpClient = new OkHttpClient.Builder()
.addInterceptor(httpLoggingInterceptor)
.writeTimeout(5, TimeUnit.SECONDS)
.readTimeout(5,TimeUnit.SECONDS)
.connectTimeout(5,TimeUnit.SECONDS)
.build();
}
public static OkHttputils getInstance(){
if (okHttputils ==null){
synchronized (OkHttputils.class){
if (okHttputils ==null){
okHttputils = new OkHttputils();
}
}
}
return okHttputils;
}
public void getData(String url, HashMap<String,String > params, final RequestCallback requestCallback){
StringBuilder urlsb = new StringBuilder();
String allUrl ="";
for (Map.Entry<String,String> stringStringEntry : params.entrySet()){
urlsb.append("?").append(stringStringEntry.getKey()).append("=").append(stringStringEntry.getValue()).append("&");
}
allUrl = url+urlsb.toString().substring(0,urlsb.length()-1);
System.out.println("url:"+ allUrl);
Request build = new Request.Builder()
.url(allUrl).get().build();
okhttpClient.newCall(build).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
if (requestCallback !=null){
requestCallback.failure(call,e);
}
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (requestCallback !=null){
requestCallback.onResponse(call,response);
}
}
});
}
public void postData(String url,HashMap<String ,String > prams,final RequestCallback requestCallback){
FormBody.Builder fromBodybuilder = new FormBody.Builder();
Log.i("aaaaa","aaaa");
if (prams != null && prams.size()>0){
for (Map.Entry<String,String > stringStringEntry : prams.entrySet()){
fromBodybuilder.add(stringStringEntry.getKey(),stringStringEntry.getValue());
}
}
Request requset = new Request.Builder()
.url(url).post(fromBodybuilder.build()).build();
okhttpClient.newCall(requset).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
if (requestCallback !=null){
requestCallback.failure(call, e);
}
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (requestCallback !=null){
requestCallback.onResponse(call, response);
}
}
});
}
}
//utils_ResponseCallback
package com.bwie.yuekao.utils;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Response;
public interface RequestCallback {
void failure(Call call, IOException e);
void onResponse(Call call, Response response);
}