//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"
android:orientation="vertical"
tools:context="com.example.gouwuche.View.MainActivity">
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp">
<CheckBox
android:id="@+id/check_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="全选"/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="总价"/>
<TextView
android:id="@+id/tv_totalprice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"/>
</LinearLayout>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#C60000"
android:textSize="24sp"
android:textColor="#ffffff"
android:text="结算"/>
</LinearLayout>
</LinearLayout>
//ITEM
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
>
<CheckBox
android:id="@+id/lv_cb"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/list_imgaer"
android:layout_toRightOf="@id/lv_cb"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@mipmap/ic_launcher"/>
<RelativeLayout
android:id="@+id/aaaa"
android:layout_toRightOf="@id/list_imgaer"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/list_name"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="xxxxxxxxxxxxxxxxxxxx"/>
<TextView
android:id="@+id/list_price"
android:layout_below="@id/list_name"
android:layout_width="wrap_content"
android:layout_marginTop="5dp"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_below="@id/list_price"
android:layout_marginTop="10dp"
android:id="@+id/ddd"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/lv_jian"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="-" />
<TextView
android:id="@+id/lv_num"
android:layout_width="50dp"
android:gravity="center"
android:layout_height="wrap_content"
android:text="-" />
<Button
android:id="@+id/lv_jia"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="+" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="@+id/shanchu"
android:layout_toRightOf="@id/aaaa"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="20dp"
android:layout_marginTop="20dp"
android:src="@drawable/rrrrrrrrr"/>
</RelativeLayout>
//MainActivity
package com.example.gouwuche.View;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;
import com.example.gouwuche.Adapter.MyAdapter;
import com.example.gouwuche.Bean.ShopingBena;
import com.example.gouwuche.Presenter.MyDataPresenter;
import com.example.gouwuche.R;
import java.util.List;
public class MainActivity extends AppCompatActivity implements DataView,MyAdapter.NumInterface {
private ListView list_view;
private CheckBox check_box;
private TextView totalprice;
private List<ShopingBena.DataBean> list;
MyAdapter adaper;
String dataUrl ="https://www.zhaoapi.cn/product/getProducts?pscid=1";
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
list = (List<ShopingBena.DataBean>) msg.obj;
adaper = new MyAdapter(MainActivity.this,list);
list_view.setAdapter(adaper);
adaper.setShoping(MainActivity.this);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list_view = (ListView) findViewById(R.id.list_view);
check_box = (CheckBox) findViewById(R.id.check_box);
totalprice = findViewById(R.id.tv_totalprice);
MyDataPresenter presenter = new MyDataPresenter(this);
presenter.netWork(dataUrl);
check_box.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (check_box.isChecked()){
for (int x= 0; x < list.size();x++){
list.get(x).setCheck(true);
}
adaper.notifyDataSetChanged();
}else{
for (int x= 0; x < list.size();x++){
list.get(x).setCheck(false);
}
adaper.notifyDataSetChanged();
}
changPrice();
}
});
}
@Override
public void jiaNum(int position, TextView tv, Boolean isCheck) {
int currentNum = list.get(position).getSellerid();
currentNum++;
list.get(position).setSellerid(currentNum);
adaper.notifyDataSetChanged();
changPrice();
}
@Override
public void jianNum(int position, TextView tv, Boolean isCheck) {
int currentNum = list.get(position).getSellerid();
if (currentNum == 1){
return;
}
currentNum--;
list.get(position).setSellerid(currentNum);
adaper.notifyDataSetChanged();
changPrice();
}
public void groupCheck(int position, boolean isCheck) {
ShopingBena.DataBean dataBean = list.get(position);
dataBean.setCheck(isCheck);
changPrice();
}
/**
*
* @param position
*/
@Override
public void chaPrice(int position) {
changPrice();
}
private void changPrice() {
int totalprices = 0;
int totalNum = 0;
for (int x = 0; x < list.size();x++){
ShopingBena.DataBean dataBean = list.get(x);
if (dataBean.getCheck()){
totalNum++;
totalprices+=list.get(x).getPrice()*list.get(x).getSellerid();
}
}
totalprice.setText(totalprices+"");
}
@Override
public void toBackHome(List<ShopingBena.DataBean> list) {
Message msg = new Message();
msg.obj = list;
handler.sendMessage(msg);
}
}
//DataView
package com.example.gouwuche.View;
import com.example.gouwuche.Bean.ShopingBena;
import java.util.List;
/**
* Created by 你家大林哥 on 2018/3/30.
*/
public interface DataView {
void toBackHome(List<ShopingBena.DataBean> list);
}
//OkhttpUtil
package com.example.gouwuche.Util;
import android.os.Environment;
import java.io.File;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import static android.R.string.ok;
import static android.os.Build.VERSION_CODES.M;
/**
* Created by Administrator on 2018/3/8.
*/
public class OkhtttpUtils {
//单例模式,把构造方法进行私有化
//
private OkhtttpUtils(){};
static OkHttpClient client;
public static OkHttpClient getInstance(){
if (client==null) {
//更加安全
synchronized (OkhtttpUtils.class) {
//缓存的地方 mnt/sdcard
File file = new File(Environment.getExternalStorageDirectory(), "cache11");
client = new OkHttpClient().newBuilder()
.readTimeout(3000, TimeUnit.SECONDS) //设置读取超时时间
.connectTimeout(3000, TimeUnit.SECONDS) //设置连接的超时时间
.cache(new Cache(file, 10 * 1024))
.build();
}
}
return client;
}
/**
* get请求
* Callback 是一个接口
*/
public static void doGet(String url, Callback callback){
//1:拿到okhttpclient 对像
OkHttpClient client = getInstance();
//2:进行请求的操作
Request request = new Request.Builder()
.url(url)
.build();
client.newCall(request).enqueue(callback);
}
//post请求
/**
*
* @param url 请求的地址
* @param parms 请求的参数
* @param callback callback
*/
public static void doPost(String url, Map<String,String> parms,Callback callback){
//得到客户端的对像
OkHttpClient client = getInstance();
//不是FormBody,而是一个Builder
FormBody.Builder body = new FormBody.Builder();
//key value
for (String key:parms.keySet()){
//value的值
body.add(key,parms.get(key));
}
Request request = new Request.Builder()
.url(url)
.post(body.build())
.build();
client.newCall(request).enqueue(callback);
}
//用来上传图片的
//url , 图片 ,参数 Callback
public static void upImage(String url,File file,String filenName,Map<String,String> params,Callback callback){
OkHttpClient client = getInstance();
//requestBody的实现类 Formbody
MultipartBody.Builder builder = new MultipartBody.Builder();
if (params!=null){
for (String key :params.keySet()){
builder.addFormDataPart(key,params.get(key));
}
}
//设置类型
builder.setType(MultipartBody.FORM);
builder.addFormDataPart("file",filenName,RequestBody.create(MediaType.parse("application/octet-stream"),file));
// builder.setType(MultipartBody.FORM);
// builder.addFormDataPart("file",filenName,RequestBody.create(MediaType.parse("application/octet-stream"),file));
//builder.addFormDataPart("file","aa.png",builder.build());
Request request = new Request.Builder()
.url(url)
.post(builder.build())
.build();
client.newCall(request).enqueue(callback);
}
}
//MyDataPresenter
package com.example.gouwuche.Presenter;
import com.example.gouwuche.Bean.ShopingBena;
import com.example.gouwuche.Moudle.MyDataMoudle;
import com.example.gouwuche.View.DataView;
import com.example.gouwuche.View.MainActivity;
import java.util.List;
/**
* Created by 你家大林哥 on 2018/3/30.
*/
public class MyDataPresenter implements DataPresenter {
private final MyDataMoudle myDataMoudle;
DataView dataView;
public MyDataPresenter(DataView dataView){
this.dataView = dataView;
myDataMoudle = new MyDataMoudle();
}
@Override
public void succeess(List<ShopingBena.DataBean> list) {
dataView.toBackHome(list);
}
@Override
public void error() {
}
public void netWork(String dataUrl){
myDataMoudle.getData(dataUrl,this);
}
}
//DataPresenter
package com.example.gouwuche.Presenter;
import com.example.gouwuche.Bean.ShopingBena;
import java.util.List;
/**
* Created by 你家大林哥 on 2018/3/30.
*/
public interface DataPresenter {
void succeess(List<ShopingBena.DataBean> list);
void error();
}
//MyDataMoudle
package com.example.gouwuche.Moudle;
import com.example.gouwuche.Bean.ShopingBena;
import com.example.gouwuche.Presenter.DataPresenter;
import com.example.gouwuche.Util.OkhtttpUtils;
import com.google.gson.Gson;
import java.io.IOException;
import java.util.List;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
/**
* Created by 你家大林哥 on 2018/3/30.
*/
public class MyDataMoudle implements DataMoudle {
@Override
public void getData(String url, final DataPresenter presenter) {
OkhtttpUtils.doGet(url, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String json = response.body().string();
Gson gson = new Gson();
ShopingBena shopingBena = gson.fromJson(json,ShopingBena.class);
List<ShopingBena.DataBean> list = shopingBena.getData();
presenter.succeess(list);
}
});
}
}
//DataMoudle
package com.example.gouwuche.Moudle;
import com.example.gouwuche.Presenter.DataPresenter;
/**
* Created by 你家大林哥 on 2018/3/30.
*/
public interface DataMoudle {
void getData(String url, DataPresenter presenter);
}
//BEAN
package com.example.gouwuche.Bean;
import java.util.List;
/**
* Created by 你家大林哥 on 2018/3/30.
*/
public class ShopingBena {
/**
* msg : 请求成功
* code : 0
* data : [{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","itemtype":1,"pid":1,"price":118,"pscid":1,"salenum":0,"sellerid":17,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","itemtype":1,"pid":2,"price":299,"pscid":1,"salenum":999,"sellerid":18,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"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"},{"bargainPrice":111.99,"createtime":"2017-10-14T21:48:08","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":2,"pid":4,"price":999,"pscid":1,"salenum":356,"sellerid":20,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","itemtype":1,"pid":5,"price":88.99,"pscid":1,"salenum":678,"sellerid":21,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"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":6,"price":7.99,"pscid":1,"salenum":234,"sellerid":22,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","itemtype":1,"pid":7,"price":120.01,"pscid":1,"salenum":1266,"sellerid":23,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"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":8,"price":324,"pscid":1,"salenum":3000,"sellerid":1,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":111.99,"createtime":"2017-10-14T21:48:08","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":2,"pid":9,"price":78.99,"pscid":1,"salenum":2356,"sellerid":2,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"},{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","itemtype":1,"pid":10,"price":555.55,"pscid":1,"salenum":0,"sellerid":3,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}]
* 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 : 111.99
* createtime : 2017-10-14T21:39:05
* detailUrl : https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends
* images : https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg
* itemtype : 1
* pid : 1
* price : 118.0
* pscid : 1
* salenum : 0
* sellerid : 17
* subhead : 每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下
* title : 北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g
*/
private double bargainPrice;
private String createtime;
private String detailUrl;
private String images;
private int itemtype;
private int pid;
private double price;
private int pscid;
private int salenum;
private int sellerid;
private String subhead;
private String title;
boolean isCheck;
public void setCheck(boolean isCheck){
this.isCheck = isCheck;
}
public boolean getCheck(){
return isCheck;
}
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;
}
}
}
//MyAdapter
package com.example.gouwuche.Adapter;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.gouwuche.Bean.ShopingBena;
import com.example.gouwuche.R;
import com.example.gouwuche.View.MainActivity;
import java.util.List;
/**
* Created by 你家大林哥 on 2018/3/30.
*/
public class MyAdapter extends BaseAdapter{
Context context;
List<ShopingBena.DataBean> list;
MainActivity numInterface;
public MyAdapter(Context context, List<ShopingBena.DataBean> list) {
this.context = context;
this.list = list;
}
public void setShoping(MainActivity numInterface) {
this.numInterface = numInterface;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null){
convertView = View.inflate(context, R.layout.list_item,null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
final String imageUrl ="https://img-my.csdn.net/uploads/201407/26/1406383264_4787.jpg";
holder.list_name.setText(list.get(position).getTitle());
holder.list_price.setText(list.get(position).getPrice()+"");
holder.lv_num.setText(list.get(position).getSellerid()+"");
holder.lv_cb.setChecked(list.get(position).getCheck());
Glide.with(context).load(imageUrl).into(holder.list_imgaer);
ShopingBena.DataBean dataBean = list.get(position);
if (dataBean.getCheck()){
dataBean.setCheck(true);
}else{
dataBean.setCheck(false);
}
holder.lv_cb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
list.get(position).setCheck(holder.lv_cb.isChecked());
numInterface.groupCheck(position,holder.lv_cb.isChecked());
}
});
holder.lv_jia.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
numInterface.jiaNum(position,holder.lv_num,holder.lv_cb.isChecked());
}
});
holder.lv_jian.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
numInterface.jianNum(position,holder.lv_num,holder.lv_cb.isChecked());
}
});
holder.shanchu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
list.remove(position);
notifyDataSetChanged();
numInterface.chaPrice(position);
}
});
return convertView;
}
class ViewHolder{
CheckBox lv_cb;
TextView list_name,list_price,lv_num;
Button lv_jian,lv_jia;
ImageView list_imgaer,shanchu;
ViewHolder(View convertView) {
lv_cb = convertView.findViewById(R.id.lv_cb);
list_name = convertView.findViewById(R.id.list_name);
list_price = convertView.findViewById(R.id.list_price);
lv_jian = convertView.findViewById(R.id.lv_jian);
lv_jia = convertView.findViewById(R.id.lv_jia);
lv_num = convertView.findViewById(R.id.lv_num);
list_imgaer = convertView.findViewById(R.id.list_imgaer);
shanchu = convertView.findViewById(R.id.shanchu);
}
}
public interface NumInterface{
void jiaNum(int position,TextView tv,Boolean isCheck);
void jianNum(int position,TextView tv,Boolean isCheck);
void groupCheck(int position,boolean isCheck);
void chaPrice(int position);
}
}
//Build
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.squareup.okhttp3:okhttp:3.10.0'
compile 'com.github.bumptech.glide:glide:3.7.0
Studio购物车
最新推荐文章于 2021-04-16 20:55:15 发布