//清单
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SousuoActivity" /> <activity android:name=".SouGoodsActivity" /> <activity android:name=".ShopGoodsActivity" /> <activity android:name=".Main2Activity"></activity>
//依赖
compile 'com.jakewharton:butterknife:8.5.1' compile 'com.google.code.gson:gson:2.8.2' compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.squareup.okhttp3:okhttp:3.9.0' compile 'com.android.support:recyclerview-v7:26.1.0' annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1' implementation 'com.android.support:design:27.0.2'//布局
//activity_main
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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:background="#000" tools:context="com.example.gouwu.MainActivity"> <com.example.gouwu.MyTitleView android:id="@+id/titleview" android:layout_width="match_parent" android:layout_height="wrap_content"></com.example.gouwu.MyTitleView> </android.support.constraint.ConstraintLayout>//activity_main2
<?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:orientation="vertical" android:layout_height="match_parent" tools:context="com.example.gouwu.Main2Activity"> <!--头布局--> <LinearLayout android:id="@+id/top_bar" android:layout_width="match_parent" android:layout_height="48dp" android:background="#f7f7f7" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="48dp" android:background="@android:color/transparent" android:orientation="vertical"> <ImageView android:id="@+id/back" android:layout_width="48dp" android:layout_height="48dp" android:layout_alignParentLeft="true" android:layout_gravity="center_vertical" android:padding="12dp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:minHeight="48dp" android:text="购物车" android:textColor="#1a1a1a" android:textSize="16sp" /> <TextView android:id="@+id/edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="40dp" android:gravity="center" android:minHeight="48dp" android:text="编辑" android:textColor="#1a1a1a" android:textSize="14sp" android:visibility="visible" /> </RelativeLayout> </LinearLayout> <ExpandableListView android:id="@+id/exListView" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:childIndicator="@null" android:groupIndicator="@null"></ExpandableListView> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center_vertical" android:orientation="horizontal"> <CheckBox android:id="@+id/all_chekbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="全选" /> <LinearLayout android:id="@+id/ll_info" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="4"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginRight="20dp" android:layout_weight="1" android:orientation="vertical"> <!--android:layout_marginLeft="150dp"--> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="合计:" android:textSize="18sp" android:textStyle="bold" /> <TextView android:id="@+id/total_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="¥0.00" android:textColor="#f23232" android:textSize="16sp" android:textStyle="bold" /> </LinearLayout> <TextView android:id="@+id/total_number" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" android:text="共有商品:0件" android:textSize="16sp" android:textStyle="bold" /> </LinearLayout> <TextView android:id="@+id/tv_go_to_pay" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="3" android:background="#fd7a05" android:clickable="true" android:gravity="center" android:text="结算" android:textColor="#FAFAFA" /> </LinearLayout> </LinearLayout> </LinearLayout>//activity_sou_suo
<?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" android:orientation="vertical" tools:context="com.example.gouwu.SousuoActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/tv_ss_close" android:layout_width="20dp" android:layout_height="20dp" android:background="@drawable/houtui" android:gravity="center" android:textSize="20dp" /> <EditText android:id="@+id/ed_ss_ss" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/shape002" android:gravity="center" android:hint="输入搜索的内容" /> <TextView android:id="@+id/btn_ss_ss" android:layout_width="70dp" android:layout_height="wrap_content" android:gravity="center" android:textColor="#000" android:text="搜索" /> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="1dp" android:background="#6109090a" /> <com.example.gouwu.XCFlowLayout android:id="@+id/flowlayout" android:layout_width="match_parent" android:layout_height="200dp"></com.example.gouwu.XCFlowLayout> <ListView android:id="@+id/ss_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:layout_weight="1"></ListView> <Button android:id="@+id/btn_ss_clear" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="#000" android:text="清空搜索记录" /> </LinearLayout>//activiry_sou_goods
<?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" android:orientation="vertical" tools:context="com.example.gouwu.SouGoodsActivity"> <TextView android:id="@+id/tv_ss_null" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:gravity="center" android:text="" android:textColor="#f90505" android:textSize="25sp" /> <android.support.v7.widget.RecyclerView android:id="@+id/ss_recycle" android:layout_width="match_parent" android:layout_height="match_parent"></android.support.v7.widget.RecyclerView> </LinearLayout>//activity_shop_goods
<?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="match_parent" tools:context="com.example.gouwu.ShopGoodsActivity"> <TextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="商品详情页" android:textColor="#000" android:textSize="25dp" /> <ImageView android:id="@+id/img_main_xq" android:layout_width="match_parent" android:layout_height="300dp" android:layout_below="@+id/textView2" android:layout_marginTop="19dp" android:src="@mipmap/ic_launcher" android:textColor="#000" /> <TextView android:id="@+id/tv_main_xq_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/img_main_xq" android:layout_marginTop="17dp" android:text="asdasdasdsa" android:textColor="#000" android:textSize="15dp" /> <TextView android:id="@+id/tv_main_xq_price" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv_main_xq_title" android:layout_marginTop="20dp" android:text="qqqqqqqqqqqq" android:textColor="#f5070f" android:textSize="15dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"> <Button android:id="@+id/btn_main_xq" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ed0707" android:text="加入购物车" /> </LinearLayout> </RelativeLayout>//title_item
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <LinearLayout android:layout_width="50dp" android:layout_height="60dp" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="8dp" /> <Button android:id="@+id/saoyisao" android:layout_width="30dp" android:layout_height="30dp" android:layout_gravity="center" android:background="@drawable/jd_title_qrcode" /> <TextView android:layout_width="30dp" android:layout_height="12dp" android:layout_gravity="center" android:text="扫一扫" android:textColor="#ffffff" android:textSize="10sp" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="60dp" android:layout_weight="1" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center"> <ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="54dp" android:layout_marginBottom="8dp" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_marginTop="8dp" android:background="@drawable/jd_title_text" /> <Button android:id="@+id/home_title_btn" android:layout_width="match_parent" android:layout_height="50dp" android:layout_alignLeft="@+id/imageView" android:layout_alignStart="@+id/imageView" android:layout_alignTop="@+id/imageView" android:background="#00000000" android:text="多功能插座" android:textSize="10dp" /> </RelativeLayout> </LinearLayout> <LinearLayout android:layout_width="50dp" android:layout_height="60dp" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="8dp" /> <Button android:id="@+id/xiaoxi" android:layout_width="30dp" android:layout_height="30dp" android:layout_gravity="center" android:background="@drawable/jd_title_msg" /> <TextView android:layout_width="30dp" android:layout_height="12dp" android:layout_gravity="center" android:gravity="center" android:text="消息" android:textColor="#ffffff" android:textSize="10sp" /> </LinearLayout> </LinearLayout>//sou_list
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:padding="10dp" android:layout_height="match_parent"> <TextView android:id="@+id/fl_list_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15dp" android:text="asdasdsa"/> </LinearLayout>//goods_item
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <ImageView android:id="@+id/img_item_zfl" android:layout_width="80dp" android:layout_height="80dp" android:src="@mipmap/ic_launcher" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" android:padding="10dp"> <TextView android:id="@+id/zfl_item_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="title" android:textColor="#000" android:textSize="15dp" /> <TextView android:id="@+id/zfl_item_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="价格:" android:textColor="#fa0000" /> </LinearLayout> </LinearLayout>//ex_child_item
<?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="230dp" android:orientation="horizontal"> <CheckBox android:id="@+id/child_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="50dp" android:layout_marginLeft="20dp" android:layout_marginTop="50dp" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="20dp"> <TextView android:id="@+id/shop_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_marginLeft="17dp" android:layout_marginStart="17dp" android:text="TextView" /> <ImageView android:id="@+id/shop_img" android:layout_width="90dp" android:layout_height="90dp" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/shop_name" android:layout_marginTop="30dp" app:srcCompat="@mipmap/ic_launcher" /> <TextView android:id="@+id/shop_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/shop_img" android:layout_centerHorizontal="true" android:layout_marginTop="10dp" android:text="¥20" android:textColor="#f23232" /> <com.example.gouwu.AddDeleteView android:id="@+id/adv" android:layout_width="160dp" android:layout_height="30dp" android:layout_below="@+id/shop_price" android:layout_marginLeft="140dp" android:layout_marginTop="30dp" android:focusable="false" app:left_text="-" app:middle_text="1" app:right_text="+"> </com.example.gouwu.AddDeleteView> <Button android:id="@+id/shop_delete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:text="删除" android:visibility="invisible" /> </RelativeLayout> </LinearLayout>//ex_group_item
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#cfc3c3" android:orientation="horizontal"> <CheckBox android:id="@+id/group_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp"/> <TextView android:id="@+id/shop_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:textSize="16dp" /> </LinearLayout>//layout_add_delete
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:weightSum="1"> <TextView android:id="@+id/txt_delete" android:layout_width="25dp" android:layout_height="25dp" android:textColor="#000000" android:text="-" android:gravity="center" android:background="@drawable/edit"/> <EditText android:id="@+id/et_number" android:layout_marginTop="1dp" android:enabled="false" android:layout_width="40dp" android:layout_height="25dp" android:background="@drawable/edit" android:layout_weight="0.00" android:textColor="#000000" android:gravity="center" android:text="1"/> <TextView android:id="@+id/txt_add" android:layout_width="25dp" android:layout_height="25dp" android:textColor="#000000" android:text="+" android:gravity="center" android:background="@drawable/edit"/> </LinearLayout>//edit.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FFFFFF" /> <!--<corners android:radius="3dip"/>--> <stroke android:width="1dip" android:color="#BDC7D8" /> </shape>
//shap002.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#f0f2f5"/> <!--设置按钮四个角为弧形--> <!--android:radius弧形的半径--> <corners android:radius="50dip"/> <!--padding;button里面的文字与button边界的间隔--> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp"/> </shape>//attrs
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="AddDeleteViewStyle"> <attr name="left_text" format="string"></attr> <attr name="right_text" format="string"></attr> <attr name="middle_text" format="string"></attr> <attr name="left_text_color" format="color"></attr> </declare-styleable> </resources>//MainActivity
package com.example.gouwu; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private MyTitleView titleview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); titleview = findViewById(R.id.titleview); titleview.setOnTitleLinsenter(new MyTitleView.onTitleLinsenter() { @Override public void setSaoYiSao(View view) { Toast.makeText(MainActivity.this, "扫一扫", Toast.LENGTH_SHORT).show(); } @Override public void setTitleBtn(View view) { Toast.makeText(MainActivity.this, "搜索", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(MainActivity.this, SousuoActivity.class); startActivity(intent); } @Override public void setXiaoXi(View view) { Toast.makeText(MainActivity.this, "消息", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(MainActivity.this, Main2Activity.class); startActivity(intent); } }); } }
//Main2Activity
package com.example.gouwu; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.CheckBox; import android.widget.ExpandableListView; import android.widget.TextView; import android.widget.Toast; import com.example.gouwu.adapter.ExpandableAdapter; import com.example.gouwu.bean.ChildBean; import com.example.gouwu.bean.GroupBean; import com.example.gouwu.bean.ShopCarBean; import com.example.gouwu.interfaces.IView; import com.example.gouwu.presenter.NewsPresenter; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main2Activity extends AppCompatActivity implements IView { //private static final String TAG = "Main2Activity数据"; private ExpandableListView exListView; public CheckBox allCheckbox; private TextView totalPrice; private TextView totalnumber; List<GroupBean> groupBeen = new ArrayList<>(); List<List<ChildBean>> childBeen = new ArrayList<>(); private NewsPresenter presenter; private ExpandableAdapter expandableAdapter; private TextView edit; private boolean flagedit = true; private boolean flag; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); getSupportActionBar().hide(); initView(); presenter = new NewsPresenter(); presenter.attachView(Main2Activity.this); Map<String, String> map = new HashMap<>(); //手动添加数据 //http://120.27.23.105/product/addCart?uid=4619&pid=70 presenter.get("http://120.27.23.105/product/getCarts?uid=2606", map, "car", ShopCarBean.class); //获取二级列表适配器 expandableAdapter = new ExpandableAdapter(Main2Activity.this, groupBeen, childBeen, this); exListView.setAdapter(expandableAdapter); for (int i = 0; i < expandableAdapter.getGroupCount(); i++) { exListView.expandGroup(i); } exListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) { return true; } }); //全选监听 allCheckbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean checked = allCheckbox.isChecked(); //改变一级item复选框 for (GroupBean i : groupBeen) { i.setGropuCb(checked); } //改变二级item复选框 for (List<ChildBean> i1 : childBeen) { for (int r = 0; r < i1.size(); r++) { i1.get(r).setChildCb(checked); } } expandableAdapter.notifyDataSetChanged(); changesum(childBeen); //Toast.makeText(Main2Activity.this,"全选按钮"+checked,Toast.LENGTH_SHORT).show(); } }); edit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (!flag) {// false 隐藏 true 代表显示 //隐藏 flag = true; expandableAdapter.showDelete(flag); edit.setText("完成"); } else { //显示 flag = false; expandableAdapter.showDelete(flag); edit.setText("编辑"); } for (List<ChildBean> i1 : childBeen) { for (int r = 0; r < i1.size(); r++) { i1.get(r).setBtn(flagedit); } } flagedit = !flagedit; expandableAdapter.notifyDataSetChanged(); } }); } //初始化控件 private void initView() { exListView = (ExpandableListView) findViewById(R.id.exListView); allCheckbox = (CheckBox) findViewById(R.id.all_chekbox); totalPrice = (TextView) findViewById(R.id.total_price); totalnumber = (TextView) findViewById(R.id.total_number); edit = (TextView) findViewById(R.id.edit); } @Override public void success(String tag, Object o) { if (o != null && tag.equals("car")) { ShopCarBean shopCarBean = (ShopCarBean) o; List<ShopCarBean.DataBean> data = shopCarBean.getData(); for (ShopCarBean.DataBean i : data) { GroupBean groupBean = new GroupBean(i.getSellerName(), false); this.groupBeen.add(groupBean); List<ShopCarBean.DataBean.ListBean> list1 = i.getList(); List<ChildBean> ls = new ArrayList<>(); for (ShopCarBean.DataBean.ListBean k : list1) { String[] split = k.getImages().split("\\|"); ChildBean childBean = new ChildBean(k.getTitle(), split[0], k.getPrice(), 1, false, false); ls.add(childBean); } this.childBeen.add(ls); } for (int i = 0; i < expandableAdapter.getGroupCount(); i++) { exListView.expandGroup(i); } expandableAdapter.notifyDataSetChanged(); } } @Override public void failed(String tag, Exception e) { Toast.makeText(Main2Activity.this, e.getMessage() + "", Toast.LENGTH_SHORT).show(); } DecimalFormat df = new DecimalFormat("######0.00"); //计算和数量总价 public void changesum(List<List<ChildBean>> childBeen) { int count = 0; double sum = 0; for (List<ChildBean> i1 : childBeen) { for (int r = 0; r < i1.size(); r++) { boolean childCb1 = i1.get(r).isChildCb(); if (childCb1) { double price = i1.get(r).getPrice(); int num = i1.get(r).getNum(); sum += price * num; count++; } } } totalPrice.setText("¥" + df.format(sum)); totalnumber.setText("共有商品:" + count + "件"); } @Override public void onDestroy() { super.onDestroy(); if (presenter != null) { presenter.deleteView(); } } }
//SousuoActivity
package com.example.gouwu; import android.content.Intent; import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.MarginLayoutParams; import android.view.ViewGroup.LayoutParams; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.example.gouwu.adapter.MySouListAdapter; import java.util.ArrayList; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; public class SousuoActivity extends AppCompatActivity { @BindView(R.id.tv_ss_close) TextView tvSsClose; @BindView(R.id.ed_ss_ss) EditText edSsSs; @BindView(R.id.btn_ss_ss) TextView btnSsSs; @BindView(R.id.ss_list) ListView ssList; @BindView(R.id.btn_ss_clear) Button btnSsClear; List<String> arr = new ArrayList<>(); private MySouListAdapter adapter; private String mNames[] = { "原谅", "我这", "一生", "不羁放纵", "爱自由", "kobe bryant", "jordan", "layout", "viewgroup", "margin", "padding", "text", "name", "type", "search", "logcat" }; private XCFlowLayout mFlowLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().hide(); setContentView(R.layout.activity_sou_suo); ButterKnife.bind(this); adapter = new MySouListAdapter(this, arr); ssList.setAdapter(adapter); initChildViews(); } private void initChildViews() { // TODO Auto-generated method stub mFlowLayout = (XCFlowLayout) findViewById(R.id.flowlayout); MarginLayoutParams lp = new ViewGroup.MarginLayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.leftMargin = 5; lp.rightMargin = 5; lp.topMargin = 5; lp.bottomMargin = 5; for (int i = 0; i < mNames.length; i++) { TextView view = new TextView(this); view.setText(mNames[i]); view.setTextColor(Color.BLACK); view.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape002)); mFlowLayout.addView(view, lp); } } @OnClick({R.id.tv_ss_close, R.id.btn_ss_ss, R.id.btn_ss_clear}) public void onViewClicked(View view) { switch (view.getId()) { case R.id.tv_ss_close: finish(); break; case R.id.btn_ss_ss: String trim = edSsSs.getText().toString().trim(); if (TextUtils.isEmpty(trim)) { Toast.makeText(this, "请输入搜索内容", Toast.LENGTH_SHORT).show(); } else { arr.add(trim); Intent intent = new Intent(this, SouGoodsActivity.class); intent.putExtra("keywords", trim); startActivity(intent); edSsSs.setText(""); adapter.notifyDataSetChanged(); } break; case R.id.btn_ss_clear: arr.clear(); adapter.notifyDataSetChanged(); break; } } }
//SouGoodsActivity
package com.example.gouwu; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.widget.TextView; import com.example.gouwu.adapter.MySouGoodsAdapter; import com.example.gouwu.bean.SouGoodsBean; import com.example.gouwu.interfaces.IView; import com.example.gouwu.presenter.NewsPresenter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import butterknife.BindView; import butterknife.ButterKnife; public class SouGoodsActivity extends AppCompatActivity implements IView { @BindView(R.id.ss_recycle) RecyclerView ssRecycle; @BindView(R.id.tv_ss_null) TextView tvSsNull; private NewsPresenter presenter; List<SouGoodsBean.DataBean> list = new ArrayList<>(); private MySouGoodsAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().hide(); setContentView(R.layout.activity_sou_goods); ButterKnife.bind(this); Intent intent = getIntent(); String keywords = intent.getStringExtra("keywords"); presenter = new NewsPresenter(); presenter.attachView(this); Map<String, String> map = new HashMap<>(); map.put("keywords", keywords); presenter.get("http://120.27.23.105/product/searchProducts", map, "sougoods", SouGoodsBean.class); ssRecycle.setLayoutManager(new LinearLayoutManager(this)); adapter = new MySouGoodsAdapter(list, this, this); ssRecycle.setAdapter(adapter); } @Override public void success(String tag, Object o) { if (o != null && tag.equals("sougoods")) { SouGoodsBean souGoodsBean = (SouGoodsBean) o; List<SouGoodsBean.DataBean> data = souGoodsBean.getData(); list.addAll(data); if (list.size() == 0) { tvSsNull.setText("暂无此类商品"); } adapter.notifyDataSetChanged(); } } @Override public void failed(String tag, Exception e) { } public void ziShopGoods(int pid) { Intent intent = new Intent(this, ShopGoodsActivity.class); intent.putExtra("uid", 2606); intent.putExtra("pid", pid); startActivity(intent); } }
//ShopGoodsActivity
package com.example.gouwu; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.bumptech.glide.Glide; import com.example.gouwu.bean.ShopGoodsBean; import com.example.gouwu.bean.ZhuCeBean; import com.example.gouwu.interfaces.IView; import com.example.gouwu.presenter.NewsPresenter; import java.util.HashMap; import java.util.Map; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; public class ShopGoodsActivity extends AppCompatActivity implements IView { @BindView(R.id.textView2) TextView textView2; @BindView(R.id.img_main_xq) ImageView imgMainXq; @BindView(R.id.tv_main_xq_title) TextView tvMainXqTitle; @BindView(R.id.tv_main_xq_price) TextView tvMainXqPrice; @BindView(R.id.btn_main_xq) Button btnMainXq; private NewsPresenter presenter; private int pid; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().hide(); setContentView(R.layout.activity_shop_goods); ButterKnife.bind(this); Intent intent = getIntent(); pid = intent.getIntExtra("pid", 0); presenter = new NewsPresenter(); presenter.attachView(this); Map<String, String> map = new HashMap<>(); map.put("pid", pid + ""); presenter.get("http://120.27.23.105/product/getProductDetail", map, "goodsxq", ShopGoodsBean.class); } @OnClick(R.id.btn_main_xq) public void onViewClicked() { Map<String, String> map = new HashMap<>(); map.put("uid", "2606"); map.put("pid", pid + ""); presenter.post("http://120.27.23.105/product/addCart", map, "addgoods", ZhuCeBean.class); } @Override public void success(String tag, Object o) { if (o != null && tag.equals("goodsxq")) { ShopGoodsBean shopGoods = (ShopGoodsBean) o; ShopGoodsBean.DataBean data = shopGoods.getData(); Glide.with(this).load(data.getImages().split("\\|")[0]).into(imgMainXq); tvMainXqTitle.setText(data.getTitle()); tvMainXqPrice.setText("商品价格: " + data.getPrice() + ""); } if (o != null && tag.equals("addgoods")) { ZhuCeBean zhuCeBean = (ZhuCeBean) o; String code = zhuCeBean.getCode(); if (code.equals("0")) { Toast.makeText(this, "添加购物车成功", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "添加购物车失败", Toast.LENGTH_SHORT).show(); } } } @Override public void failed(String tag, Exception e) { } }
//XCFlowLayout
// MyTitleViewpackage com.example.gouwu; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; public class XCFlowLayout extends ViewGroup { //存储所有子View private List<List<View>> mAllChildViews = new ArrayList<>(); //每一行的高度 private List<Integer> mLineHeight = new ArrayList<>(); public XCFlowLayout(Context context) { this(context, null); // TODO Auto-generated constructor stub } public XCFlowLayout(Context context, AttributeSet attrs) { this(context, attrs, 0); // TODO Auto-generated constructor stub } public XCFlowLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub //父控件传进来的宽度和高度以及对应的测量模式 int sizeWidth = MeasureSpec.getSize(widthMeasureSpec); int modeWidth = MeasureSpec.getMode(widthMeasureSpec); int sizeHeight = MeasureSpec.getSize(heightMeasureSpec); int modeHeight = MeasureSpec.getMode(heightMeasureSpec); //如果当前ViewGroup的宽高为wrap_content的情况 int width = 0;//自己测量的 宽度 int height = 0;//自己测量的高度 //记录每一行的宽度和高度 int lineWidth = 0; int lineHeight = 0; //获取子view的个数 int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); //测量子View的宽和高 measureChild(child, widthMeasureSpec, heightMeasureSpec); //得到LayoutParams MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams(); //子View占据的宽度 int childWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; //子View占据的高度 int childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin; //换行时候 if (lineWidth + childWidth > sizeWidth) { //对比得到最大的宽度 width = Math.max(width, lineWidth); //重置lineWidth lineWidth = childWidth; //记录行高 height += lineHeight; lineHeight = childHeight; } else {//不换行情况 //叠加行宽 lineWidth += childWidth; //得到最大行高 lineHeight = Math.max(lineHeight, childHeight); } //处理最后一个子View的情况 if (i == childCount - 1) { width = Math.max(width, lineWidth); height += lineHeight; } } //wrap_content setMeasuredDimension(modeWidth == MeasureSpec.EXACTLY ? sizeWidth : width, modeHeight == MeasureSpec.EXACTLY ? sizeHeight : height); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub mAllChildViews.clear(); mLineHeight.clear(); //获取当前ViewGroup的宽度 int width = getWidth(); int lineWidth = 0; int lineHeight = 0; //记录当前行的view List<View> lineViews = new ArrayList<View>(); int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View child = getChildAt(i); MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); int childWidth = child.getMeasuredWidth(); int childHeight = child.getMeasuredHeight(); //如果需要换行 if (childWidth + lineWidth + lp.leftMargin + lp.rightMargin > width) { //记录LineHeight mLineHeight.add(lineHeight); //记录当前行的Views mAllChildViews.add(lineViews); //重置行的宽高 lineWidth = 0; lineHeight = childHeight + lp.topMargin + lp.bottomMargin; //重置view的集合 lineViews = new ArrayList(); } lineWidth += childWidth + lp.leftMargin + lp.rightMargin; lineHeight = Math.max(lineHeight, childHeight + lp.topMargin + lp.bottomMargin); lineViews.add(child); } //处理最后一行 mLineHeight.add(lineHeight); mAllChildViews.add(lineViews); //设置子View的位置 int left = 0; int top = 0; //获取行数 int lineCount = mAllChildViews.size(); for (int i = 0; i < lineCount; i++) { //当前行的views和高度 lineViews = mAllChildViews.get(i); lineHeight = mLineHeight.get(i); for (int j = 0; j < lineViews.size(); j++) { View child = lineViews.get(j); //判断是否显示 if (child.getVisibility() == View.GONE) { continue; } MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); int cLeft = left + lp.leftMargin; int cTop = top + lp.topMargin; int cRight = cLeft + child.getMeasuredWidth(); int cBottom = cTop + child.getMeasuredHeight(); //进行子View进行布局 child.layout(cLeft, cTop, cRight, cBottom); left += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; } left = 0; top += lineHeight; } } /** * 与当前ViewGroup对应的LayoutParams */ @Override public LayoutParams generateLayoutParams(AttributeSet attrs) { // TODO Auto-generated method stub return new MarginLayoutParams(getContext(), attrs); } }
package com.example.gouwu; import android.content.Context; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; public class MyTitleView extends LinearLayout { private static onTitleLinsenter onTitleLinsenter; public interface onTitleLinsenter { void setSaoYiSao(View view); void setTitleBtn(View view); void setXiaoXi(View view); } public void setOnTitleLinsenter(MyTitleView.onTitleLinsenter onTitleLinsenter) { MyTitleView.onTitleLinsenter = onTitleLinsenter; } public MyTitleView(Context context) { this(context, null); } public MyTitleView(Context context, @Nullable AttributeSet attrs) { this(context, attrs, 0); } public MyTitleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initView(context, attrs, defStyleAttr); } private void initView(final Context context, AttributeSet attrs, int defStyleAttr) { View view = View.inflate(context, R.layout.title_item, this); Button saoyisao = view.findViewById(R.id.saoyisao); Button titlebtn = view.findViewById(R.id.home_title_btn); Button xiaoxi = view.findViewById(R.id.xiaoxi); saoyisao.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onTitleLinsenter.setSaoYiSao(v); } }); titlebtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onTitleLinsenter.setTitleBtn(v); } }); xiaoxi.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onTitleLinsenter.setXiaoXi(v); } }); } }//AddDeleteView
package com.example.gouwu; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; import android.util.AttributeSet; import android.view.View; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; public class AddDeleteView extends LinearLayout { private OnAddDelClickListener listener; private EditText etNumber; private TextView txtDelete; private TextView txtAdd; //对外提供一个点击的回调接口 public interface OnAddDelClickListener { void onAddClick(View v); void onDelClick(View v); } public void setOnAddDelClickListener(OnAddDelClickListener listener) { if (listener != null) { this.listener = listener; } } public AddDeleteView(Context context) { this(context, null); } public AddDeleteView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public AddDeleteView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initView(context, attrs, defStyleAttr); } private void initView(Context context, AttributeSet attrs, int defStyleAttr) { View.inflate(context, R.layout.layout_add_delete, this); //获取控件 txtDelete = findViewById(R.id.txt_delete); txtAdd = findViewById(R.id.txt_add); etNumber = findViewById(R.id.et_number); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.AddDeleteViewStyle); String leftText = typedArray.getString(R.styleable.AddDeleteViewStyle_left_text); String rightText = typedArray.getString(R.styleable.AddDeleteViewStyle_right_text); String middleText = typedArray.getString(R.styleable.AddDeleteViewStyle_middle_text); int color = typedArray.getColor(R.styleable.AddDeleteViewStyle_left_text_color, Color.BLACK); txtDelete.setText(leftText); txtAdd.setText(rightText); etNumber.setText(middleText); txtDelete.setTextColor(color); //回收 typedArray.recycle(); txtDelete.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { listener.onDelClick(view); } }); txtAdd.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { listener.onAddClick(view); } }); } //对外提供一个修改数字的方法 public void setNumber(int number) { if (number > 0) { etNumber.setText(number + ""); } } //对外提供一个获取当前数字的方法 public int getNumber() { String string = etNumber.getText().toString(); int i = Integer.parseInt(string); return i; } }
//adapter
//ExpandableAdapter
package com.example.gouwu.adapter; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; import com.example.gouwu.AddDeleteView; import com.example.gouwu.Main2Activity; import com.example.gouwu.R; import com.example.gouwu.bean.ChildBean; import com.example.gouwu.bean.GroupBean; import com.example.gouwu.interfaces.Cfrag; import java.util.ArrayList; import java.util.List; public class ExpandableAdapter extends BaseExpandableListAdapter implements Cfrag { // private static final String TAG = "ExpandableAdapter二级列表适配器"; private Context context; private List<GroupBean> groupBeen = new ArrayList<>(); private List<List<ChildBean>> childBeen = new ArrayList<>(); private Main2Activity main; private boolean isVisible; public ExpandableAdapter(Context context, List<GroupBean> groupBeen, List<List<ChildBean>> childBeen, Main2Activity main) { this.context = context; this.groupBeen = groupBeen; this.childBeen = childBeen; this.main = main; } @Override public int getGroupCount() { return groupBeen.size(); } @Override public int getChildrenCount(int i) { return childBeen.get(i).size(); } @Override public Object getGroup(int i) { return groupBeen.get(i).getSellerName(); } @Override public Object getChild(int i, int i1) { return childBeen.get(i).get(i1).getTitle(); } @Override public long getGroupId(int i) { return i; } @Override public long getChildId(int i, int i1) { return i1; } @Override public boolean hasStableIds() { return false; } public void showDelete(boolean isVisible) { this.isVisible = isVisible; notifyDataSetChanged(); } //一级组 @Override public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) { //加载视图 view = View.inflate(context, R.layout.ex_group_item, null); final CheckBox groupCb = view.findViewById(R.id.group_checkbox); TextView shopName = view.findViewById(R.id.shop_name); shopName.setText(groupBeen.get(i).getSellerName()); groupCb.setChecked(groupBeen.get(i).isGropuCb()); //组复选按钮 groupCb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean gchecked = groupCb.isChecked(); groupBeen.get(i).setGropuCb(gchecked); for (GroupBean i : groupBeen) { boolean gropuCb = i.isGropuCb(); if (!gropuCb) { main.allCheckbox.setChecked(false); break; } else { main.allCheckbox.setChecked(true); } } int size = childBeen.get(i).size(); if (gchecked) { for (int r = 0; r < size; r++) { //Toast.makeText(context, "group按钮" + gchecked + "" + size, Toast.LENGTH_SHORT).show(); childBeen.get(i).get(r).setChildCb(true); } } else { for (int r = 0; r < size; r++) { //Toast.makeText(context, "group按钮" + gchecked + "" + size, Toast.LENGTH_SHORT).show(); childBeen.get(i).get(r).setChildCb(false); } } notifyDataSetChanged(); main.changesum(childBeen); } }); return view; } //二级组 @Override public View getChildView(final int i, final int i1, boolean b, View v, ViewGroup viewGroup) { //加载视图 v = View.inflate(context, R.layout.ex_child_item, null); final CheckBox childCb = v.findViewById(R.id.child_checkbox); TextView shopTitle = v.findViewById(R.id.shop_title); TextView shopPrice = v.findViewById(R.id.shop_price); ImageView shopImg = v.findViewById(R.id.shop_img); final AddDeleteView adv = v.findViewById(R.id.adv); Button shop_delete = v.findViewById(R.id.shop_delete); childCb.setChecked(childBeen.get(i).get(i1).isChildCb()); Glide.with(context).load(childBeen.get(i).get(i1).getImages()).into(shopImg); shopTitle.setText(childBeen.get(i).get(i1).getTitle()); shopPrice.setText("¥" + childBeen.get(i).get(i1).getPrice()); adv.setNumber(childBeen.get(i).get(i1).getNum()); //控制删除按钮的显隐 if (childBeen.get(i).get(i1).isBtn()) { shop_delete.setVisibility(View.VISIBLE); } else { shop_delete.setVisibility(View.INVISIBLE); } //删除按钮监听 shop_delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { int size = childBeen.get(i).size(); if (size == 1) { childBeen.remove(i); groupBeen.remove(i); } else { childBeen.get(i).remove(i1); } //点击删除后隐藏所有删除按钮 for (List<ChildBean> i1 : childBeen) { for (int r = 0; r < i1.size(); r++) { i1.get(r).setBtn(false); } } notifyDataSetChanged(); main.changesum(childBeen); } }); //加减器逻辑 adv.setOnAddDelClickListener(new AddDeleteView.OnAddDelClickListener() { @Override public void onAddClick(View v) { int number = adv.getNumber(); number++; adv.setNumber(number); childBeen.get(i).get(i1).setNum(number); main.changesum(childBeen); } @Override public void onDelClick(View v) { int number = adv.getNumber(); number--; adv.setNumber(number); childBeen.get(i).get(i1).setNum(number); main.changesum(childBeen); } }); //二级组的复选框监听 childCb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean flag = false; boolean cchecked = childCb.isChecked(); childBeen.get(i).get(i1).setChildCb(cchecked); //Toast.makeText(context,"child按钮"+ cchecked+""+i1, Toast.LENGTH_SHORT).show(); for (List<ChildBean> i1 : childBeen) { for (int r = 0; r < i1.size(); r++) { boolean childCb1 = i1.get(r).isChildCb(); if (!childCb1) { main.allCheckbox.setChecked(false); groupBeen.get(i).setGropuCb(false); flag = true; break; } else { main.allCheckbox.setChecked(true); groupBeen.get(i).setGropuCb(true); } } if (flag) { break; } } int size = childBeen.get(i).size(); for (int x = 0; x < size; x++) { boolean childCb1 = childBeen.get(i).get(x).isChildCb(); if (!childCb1) { groupBeen.get(i).setGropuCb(false); break; } else { groupBeen.get(i).setGropuCb(true); } } notifyDataSetChanged(); main.changesum(childBeen); } }); return v; } @Override public boolean isChildSelectable(int i, int i1) { return false; } @Override public void getCarFrag(Main2Activity a) { this.main = a; } }
//MySouGoodsAdapter
package com.example.gouwu.adapter; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.bumptech.glide.Glide; import com.example.gouwu.R; import com.example.gouwu.SouGoodsActivity; import com.example.gouwu.bean.SouGoodsBean; import java.util.List; public class MySouGoodsAdapter extends RecyclerView.Adapter<MySouGoodsAdapter.ViewHodler> { List<SouGoodsBean.DataBean> list; Context context; SouGoodsActivity souGoodsActivity; public MySouGoodsAdapter(List<SouGoodsBean.DataBean> list, Context context, SouGoodsActivity souGoodsActivity) { this.list = list; this.context = context; this.souGoodsActivity = souGoodsActivity; } @Override public ViewHodler onCreateViewHolder(ViewGroup parent, int viewType) { View inflate = View.inflate(context, R.layout.goods_item, null); ViewHodler hodler = new ViewHodler(inflate); return hodler; } @Override public void onBindViewHolder(ViewHodler holder, final int position) { Glide.with(context).load(list.get(position).getImages().split("\\|")[0]).into(holder.images); holder.title.setText(list.get(position).getTitle()); holder.price.setText(list.get(position).getPrice() + ""); holder.title.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { souGoodsActivity.ziShopGoods(list.get(position).getPid()); } }); holder.price.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { souGoodsActivity.ziShopGoods(list.get(position).getPid()); } }); holder.images.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { souGoodsActivity.ziShopGoods(list.get(position).getPid()); } }); } @Override public int getItemCount() { if (list != null) { return list.size(); } return 0; } class ViewHodler extends RecyclerView.ViewHolder { TextView title, price; ImageView images; public ViewHodler(View itemView) { super(itemView); images = itemView.findViewById(R.id.img_item_zfl); title = itemView.findViewById(R.id.zfl_item_title); price = itemView.findViewById(R.id.zfl_item_price); } } }
//MySouListAdapter
package com.example.gouwu.adapter; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.example.gouwu.R; import java.util.List; public class MySouListAdapter extends BaseAdapter { Context context; List<String> list; public MySouListAdapter(Context context, List<String> list) { this.context = context; this.list = list; } @Override public int getCount() { if (list == null) { return 0; } 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 holder; if (convertView == null) { holder = new ViewHolder(); convertView = View.inflate(context, R.layout.sou_list, null); holder.name = convertView.findViewById(R.id.fl_list_name); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.name.setText(list.get(position)); return convertView; } class ViewHolder { TextView name; } }//interfaces
//CallBack
package com.example.gouwu.interfaces; public interface CallBack { void onSuccess(String tag, Object o); void onFailed(String tag, Exception e); }
//Cfrag
package com.example.gouwu.interfaces; import com.example.gouwu.Main2Activity; public interface Cfrag { void getCarFrag(Main2Activity car); }//IView
package com.example.gouwu.interfaces; public interface IView { void success(String tag, Object o); void failed(String tag, Exception e); }//presenter
//NewsPresenter
package com.example.gouwu.presenter; import com.example.gouwu.interfaces.CallBack; import com.example.gouwu.interfaces.IView; import com.example.gouwu.utils.HttpUtils; import java.util.Map; public class NewsPresenter { private IView inv; public void attachView(IView inv) { this.inv = inv; } public void get(String url, Map<String, String> map, String tag, Class cla) { HttpUtils.getInstance().get(url, map, new CallBack() { @Override public void onSuccess(String tag, Object o) { if (o != null) { inv.success(tag, o); } } @Override public void onFailed(String tag, Exception e) { inv.failed(tag, e); } }, cla, tag); } public void post(String url, Map<String, String> map, String tag, Class cla) { HttpUtils.getInstance().post(url, map, new CallBack() { @Override public void onSuccess(String tag, Object o) { if (o != null) { inv.success(tag, o); } } @Override public void onFailed(String tag, Exception e) { inv.failed(tag, e); } }, cla, tag); } public void deleteView() { if (inv != null) { inv = null; } } }//GsonUtils
package com.example.gouwu.utils; import com.google.gson.Gson; public class GsonUtils { private static Gson gson; public static Gson getInstance() { if (gson == null) { gson = new Gson(); } return gson; } }//HttpUtils
package com.example.gouwu.utils; import android.os.Handler; import android.text.TextUtils; import com.example.gouwu.interfaces.CallBack; import java.io.IOException; import java.util.Map; import okhttp3.Call; import okhttp3.Callback; import okhttp3.FormBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class HttpUtils { private static volatile HttpUtils instance; private OkHttpClient client; Handler handler = new Handler(); private HttpUtils() { client = new OkHttpClient.Builder().addInterceptor(new Logger()).build(); } public static HttpUtils getInstance() { if (null == instance) { synchronized (HttpUtils.class) { if (instance == null) { instance = new HttpUtils(); } } } return instance; } public void get(String url, Map<String, String> map, final CallBack callBack, final Class cla, final String tag) { if (TextUtils.isEmpty(url)) { return; } StringBuffer sb = new StringBuffer(); sb.append(url); if (!map.isEmpty()) { if (url.contains("?")) { if (url.indexOf("?") == url.length() - 1) { } else { sb.append("&"); } } else { sb.append("?"); } for (Map.Entry<String, String> entry : map.entrySet()) { sb.append(entry.getKey()) .append("=") .append(entry.getValue().trim()) .append("&"); } if (sb.indexOf("&") != -1) { sb.deleteCharAt(sb.lastIndexOf("&")); } } final Request request = new Request.Builder() .get() .url(sb.toString()) .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.onFailed(tag, e); } }); } @Override public void onResponse(Call call, Response response) throws IOException { final String result = response.body().string(); handler.post(new Runnable() { @Override public void run() { Object o; if (TextUtils.isEmpty(result)) { o = null; } else { o = GsonUtils.getInstance().fromJson(result, cla); } callBack.onSuccess(tag, o); } }); } }); } public void post(String url, Map<String, String> map, final CallBack callBack, final Class cla, final String tag) { if (TextUtils.isEmpty(url)) { return; } OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new Logger()).build(); FormBody.Builder BodyBuilder = new FormBody.Builder(); if (!map.isEmpty() && map != null) { for (Map.Entry<String, String> entry : map.entrySet()) { BodyBuilder.add(entry.getKey(), entry.getValue()); } } FormBody body = BodyBuilder.build(); final Request request = new Request.Builder() .post(body) .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.onFailed(tag, e); } }); } @Override public void onResponse(Call call, Response response) throws IOException { final String result = response.body().string(); handler.post(new Runnable() { @Override public void run() { Object o; if (TextUtils.isEmpty(result)) { o = null; } else { o = GsonUtils.getInstance().fromJson(result, cla); } callBack.onSuccess(tag, o); } }); } }); } }//Logger
package com.example.gouwu.utils; import java.io.IOException; import okhttp3.HttpUrl; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response; //拦截器 public class Logger implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Request original = chain.request(); HttpUrl url = original.url().newBuilder() .addQueryParameter("source", "android") .build(); //添加请求头 Request request = original.newBuilder() .url(url) .build(); return chain.proceed(request); } } //ChildBean
package com.example.gouwu.bean; public class ChildBean { private String title; private String images; private double price; private int num; private boolean childCb; private boolean btn; public ChildBean(String title, String images, double price, int num, boolean childCb, boolean btn) { this.title = title; this.images = images; this.price = price; this.num = num; this.childCb = childCb; this.btn = btn; } public boolean isBtn() { return btn; } public void setBtn(boolean btn) { this.btn = btn; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getImages() { return images; } public void setImages(String images) { this.images = images; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } public boolean isChildCb() { return childCb; } public void setChildCb(boolean childCb) { this.childCb = childCb; } @Override public String toString() { return "ChildBean{" + "title='" + title + '\'' + ", images='" + images + '\'' + ", price=" + price + ", num=" + num + ", childCb=" + childCb + '}'; } }
//GroupBean
package com.example.gouwu.bean; public class GroupBean { private String sellerName; private boolean gropuCb; public GroupBean(String sellerName, boolean gropuCb) { this.sellerName = sellerName; this.gropuCb = gropuCb; } public String getSellerName() { return sellerName; } public void setSellerName(String sellerName) { this.sellerName = sellerName; } public boolean isGropuCb() { return gropuCb; } public void setGropuCb(boolean gropuCb) { this.gropuCb = gropuCb; } @Override public String toString() { return "GroupBean{" + "sellerName='" + sellerName + '\'' + ", gropuCb=" + gropuCb + '}'; } }
//ShopCarBean
package com.example.gouwu.bean; import java.util.List; public class ShopCarBean { /** * code : 0 * data : [{"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":2,"pid":24,"price":288,"pscid":2,"selected":0,"sellerid":1,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}],"sellerName":"商家1","sellerid":"1"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","num":1,"pid":58,"price":6399,"pscid":40,"selected":0,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"},{"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":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":84,"pid":10,"price":555.55,"pscid":1,"selected":0,"sellerid":3,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家3","sellerid":"3"},{"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":61,"price":14999,"pscid":40,"selected":0,"sellerid":5,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家5","sellerid":"5"},{"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"}],"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":69,"price":16999,"pscid":40,"selected":0,"sellerid":13,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家13","sellerid":"13"},{"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":1,"pid":1,"price":118,"pscid":1,"selected":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家17","sellerid":"17"},{"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":1,"pid":2,"price":299,"pscid":1,"selected":0,"sellerid":18,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家18","sellerid":"18"}] * msg : 请求成功 */ private String code; private String msg; private List<DataBean> data; public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } public static class DataBean { /** * 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":2,"pid":24,"price":288,"pscid":2,"selected":0,"sellerid":1,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}] * sellerName : 商家1 * sellerid : 1 */ 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 : 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 : 2 * pid : 24 * price : 288.0 * pscid : 2 * selected : 0 * sellerid : 1 * subhead : 三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》 * title : 三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋 */ 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(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 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(double 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; } } } }// ShopGoodsBean
package com.example.gouwu.bean; public class ShopGoodsBean { /** * msg : * seller : {"description":"我是商家19","icon":"http://120.27.23.105/images/icon.png","name":"商家19","productNums":999,"score":5,"sellerid":19} * code : 0 * data : {"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","itemtype":0,"pid":3,"price":198,"pscid":1,"salenum":1234,"sellerid":19,"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 : 我是商家19 * icon : http://120.27.23.105/images/icon.png * name : 商家19 * productNums : 999 * score : 5.0 * sellerid : 19 */ 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-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 * itemtype : 0 * pid : 3 * price : 198.0 * pscid : 1 * salenum : 1234 * sellerid : 19 * 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; } } }
//SouGoodsBean
package com.example.gouwu.bean; import java.util.List; public class SouGoodsBean { /** * msg : 查询成功 * code : 0 * data : [{"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","itemtype":0,"pid":57,"price":5199,"pscid":40,"salenum":4343,"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":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","itemtype":1,"pid":58,"price":6399,"pscid":40,"salenum":545,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"},{"bargainPrice":5599,"createtime":"2017-10-10T17:30:32","detailUrl":"https://item.m.jd.com/product/4824715.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n12/jfs/t7768/184/1153704394/148460/f42e1432/599a930fN8a85626b.jpg!q70.jpg","itemtype":0,"pid":59,"price":5599,"pscid":40,"salenum":675,"sellerid":3,"subhead":"游戏本选择4G独显,拒绝掉帧】升级版IPS全高清防眩光显示屏,WASD方向键颜色加持,三大出风口立体散热!","title":"戴尔DELL灵越游匣15PR-6648B GTX1050 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 128GSSD+1T 4G独显 IPS)黑"},{"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","itemtype":2,"pid":60,"price":13888,"pscid":40,"salenum":466,"sellerid":4,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"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":61,"price":14999,"pscid":40,"salenum":5535,"sellerid":5,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"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","itemtype":0,"pid":62,"price":15999,"pscid":40,"salenum":43,"sellerid":6,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"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":63,"price":10000,"pscid":40,"salenum":3232,"sellerid":7,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-03T23:43:53","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":0,"pid":64,"price":11000,"pscid":40,"salenum":0,"sellerid":8,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"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","itemtype":2,"pid":65,"price":12000,"pscid":40,"salenum":868,"sellerid":9,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"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":66,"price":13000,"pscid":40,"salenum":7676,"sellerid":10,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}] * page : 1 */ private String msg; private String code; private String page; 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 String getPage() { return page; } public void setPage(String page) { this.page = page; } public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } public static class DataBean { /** * bargainPrice : 11800.0 * 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 * itemtype : 0 * pid : 57 * price : 5199.0 * pscid : 40 * salenum : 4343 * 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 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; } } }// ZhuCeBean
package com.example.gouwu.bean; public class ZhuCeBean { /** * msg : 天呢!用户已注册 * code : 1 */ private String msg; private String code; 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; } }