- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章RxJava+Retrofit+Mvp实现购物车由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家分享了rxjava retrofit实现购物车展示的具体代码,供大家参考,具体内容如下 。
先给大家展示一下效果图 。
框架结构:
1.项目框架:mvp,图片加载用fresco,网络请求用okhttp+retrofit实现(自己封装,加单例模式), 2.完成购物车数据添加(如果接口无数据,可用接口工具添加数据), 3.自定义view实现加减按钮,每次点击加减,item中的总数及总价要做出相应的改变。 4.当数量为1时,点击减号,数量不变,吐司提示用户最小数量为1。 5.底部总数及总价为所有item项中的总价及总数,每个item中数量价格的更改,底部总价总数要与之联动 6.实现单选反选全选功能,首次进入默认全选,item未选中时总数及总价不计入底部数据,改变选中状态时,底部总数及总价能做出正确修改 7.点击删除按钮,删除item,底部总数及总价能做出正确修改,接口数据删除.
添加所需要的依赖和联网权限 。
1
2
3
4
5
6
7
8
|
compile
'com.squareup.retrofit2:retrofit:2.0.0-beta4'
//retrofit2所需要的包
compile
'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
//converterfactory的gson依赖包
compile
'com.squareup.retrofit2:converter-scalars:2.0.0-beta4'
//converterfactory的string依赖包
compile
'io.reactivex.rxjava2:rxjava:2.1.3'
compile
'io.reactivex.rxjava2:rxandroid:2.0.1'
compile
'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile
'de.greenrobot:eventbus:3.0.0-beta1'
compile
'com.facebook.fresco:fresco:0.11.0'
|
1
|
<uses-permission android:name=
"android.permission.internet"
/>
|
在使用mvp模式前先分包 。
net包 。
api 。
1
2
3
|
public
class
api {
public
static
string host=
"http://120.27.23.105/product/"
;
}
|
serviceapi 。
1
2
3
4
5
6
7
8
|
public
interface
serviceapi {
@get
(
"getproductdetail"
)
flowable<xqbean> getxq(
@query
(
"pid"
)
int
pid,
@query
(
"source"
)string str);
@get
(
"addcart"
)
flowable<addcart> getmsg(
@query
(
"uid"
)
int
uid,
@query
(
"pid"
)
int
pid,
@query
(
"source"
)string str);
@get
(
"getcarts"
)
flowable<cartbean> getcart(
@query
(
"uid"
)
int
uid,
@query
(
"source"
)string str);
}
|
成功的接口 。
1
2
3
|
public
interface
onnetlisenter<t> {
void
success(t t);
}
|
retrofit的封装 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
public
class
retrofithepler {
public
static
okhttpclient okhttpclient;
public
static
serviceapi serviceapi;
/**
* 优先执行
*/
static
{
getokhttpclient();
}
public
static
okhttpclient getokhttpclient(){
if
(okhttpclient==
null
){
synchronized
(okhttpclient.
class
){
if
(okhttpclient==
null
){
okhttpclient=
new
okhttpclient();
}
}
}
return
okhttpclient;
}
public
static
serviceapi getserviceapi(){
if
(serviceapi==
null
){
synchronized
(okhttpclient.
class
){
if
(serviceapi==
null
){
serviceapi=oncreate(serviceapi.
class
,api.host);
}
}
}
return
serviceapi;
}
public
static
<t> t oncreate(
class
<t>tclass,string url){
retrofit retrofit =
new
retrofit.builder()
.baseurl(url)
.addconverterfactory(gsonconverterfactory.create())
.client(okhttpclient)
.addcalladapterfactory(rxjava2calladapterfactory.create())
//.addcalladapterfactory(rxjava2calladapterfactory.create())
.build();
return
retrofit.create(tclass);
}
}
|
bean包 。
详情页的bean类 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
public
class
xqbean {
/**
* msg :
* seller : {"description":"我是商家2","icon":"http://120.27.23.105/images/icon.png","name":"商家2","productnums":999,"score":5,"sellerid":2}
* code : 0
* data : {"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"}
*/
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 : 我是商家2
* icon : http://120.27.23.105/images/icon.png
* name : 商家2
* productnums : 999
* score : 5.0
* sellerid : 2
*/
private
string description;
private
string icon;
private
string name;
private
int
productnums;
private
double
score;
private
int
sellerid;
public
string getdescription() {
return
description;
}
public
void
setdescription(string description) {
this
.description = description;
}
public
string geticon() {
return
icon;
}
public
void
seticon(string icon) {
this
.icon = icon;
}
public
string getname() {
return
name;
}
public
void
setname(string name) {
this
.name = name;
}
public
int
getproductnums() {
return
productnums;
}
public
void
setproductnums(
int
productnums) {
this
.productnums = productnums;
}
public
double
getscore() {
return
score;
}
public
void
setscore(
double
score) {
this
.score = score;
}
public
int
getsellerid() {
return
sellerid;
}
public
void
setsellerid(
int
sellerid) {
this
.sellerid = sellerid;
}
}
public
static
class
databean {
/**
* bargainprice : 111.99
* createtime : 2017-10-14t21: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
*/
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;
}
}
}
|
加入购物车的bean 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public
class
addcart {
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;
}
}
|
商品类 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
public
class
cartbean {
/**
* msg : 请求成功
* 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":1,"pid":24,"price":288,"pscid":2,"selected":0,"sellerid":1,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"},{"bargainprice":11800,"createtime":"2017-10-10t17:33:37","detailurl":"https://item.m.jd.com/product/4338107.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=qqfriends","images":"https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5nc3a7dab5.jpg!q70.jpg","num":2,"pid":57,"price":5199,"pscid":40,"selected":0,"sellerid":1,"subhead":"【i5 mx150 2g显存】全高清窄边框 8g内存 256固态硬盘 支持指纹识别 预装win10系统","title":"小米(mi)air 13.3英寸全金属轻薄笔记本(i5-7200u 8g 256g pcle ssd mx150 2g独显 fhd 指纹识别 win10)银 "},{"bargainprice":99,"createtime":"2017-10-14t21:38:26","detailurl":"https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=qqfriends","images":"https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12n5b900606.jpg!q70.jpg","num":1,"pid":45,"price":2999,"pscid":39,"selected":0,"sellerid":1,"subhead":"高清双摄,就是清晰!2000+1600万高清摄像头,6gb大内存+高通骁龙835处理器,性能怪兽!","title":"一加手机5 (a5000) 6gb+64gb 月岩灰 全网通 双卡双待 移动联通电信4g手机"}],"sellername":"商家1","sellerid":"1"},{"list":[{"bargainprice":6666,"createtime":"2017-10-10t16:01:31","detailurl":"https://item.m.jd.com/product/5089273.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=qqfriends","images":"https://m.360buyimg.com/n0/jfs/t8284/363/1326459580/71585/6d3e8013/59b857f2n6ca75622.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9346/182/1406837243/282106/68af5b54/59b8480ane8af7f5c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8434/54/1359766007/56140/579509d9/59b85801nfea207db.jpg!q70.jpg","num":1,"pid":46,"price":234,"pscid":39,"selected":0,"sellerid":2,"subhead":"【iphone新品上市】新一代iphone,让智能看起来更不一样","title":"apple iphone 8 plus (a1864) 64gb 金色 移动联通电信4g手机"}],"sellername":"商家2","sellerid":"2"},{"list":[{"bargainprice":111.99,"createtime":"2017-10-03t23:43:53","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":5,"pid":12,"price":256,"pscid":1,"selected":0,"sellerid":5,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellername":"商家5","sellerid":"5"},{"list":[{"bargainprice":11800,"createtime":"2017-10-03t23:53:28","detailurl":"https://mitem.jd.hk/ware/view.action?wareid=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7n107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276can5a7d6357.jpg!q70.jpg","num":1,"pid":62,"price":15999,"pscid":40,"selected":0,"sellerid":6,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款apple macbook pro 苹果笔记本电脑 银色vp2新13英寸bar i5/8g/256g"}],"sellername":"商家6","sellerid":"6"},{"list":[{"bargainprice":399,"createtime":"2017-10-03t23:53:28","detailurl":"https://item.m.jd.com/product/1439822107.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=qqfriends","images":"https://m.360buyimg.com/n0/jfs/t5887/201/859509257/69994/6bde9bf6/59224c24ne854e14c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24n3324d5f4.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281/59224c24n3324d5f4.jpg!q70.jpg","num":1,"pid":86,"price":777,"pscid":85,"selected":0,"sellerid":7,"subhead":"满2件,总价打6.50折","title":"gap男装 休闲舒适简约水洗五袋直筒长裤紧身牛仔裤941825 深灰色 33/32(175/84a)"}],"sellername":"商家7","sellerid":"7"},{"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":12,"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":4,"pid":2,"price":299,"pscid":1,"selected":0,"sellerid":18,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellername":"商家18","sellerid":"18"},{"list":[{"bargainprice":11800,"createtime":"2017-10-03t23:53:28","detailurl":"https://mitem.jd.hk/ware/view.action?wareid=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7n107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276can5a7d6357.jpg!q70.jpg","num":1,"pid":76,"price":37999.99,"pscid":40,"selected":0,"sellerid":20,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款apple macbook pro 苹果笔记本电脑 银色vp2新13英寸bar i5/8g/256g"}],"sellername":"商家20","sellerid":"20"},{"list":[{"bargainprice":111.99,"createtime":"2017-10-14t21:39:05","detailurl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=qqfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1n9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1n7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbnd989ba0a.jpg!q70.jpg","num":1,"pid":5,"price":88.99,"pscid":1,"selected":0,"sellerid":21,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellername":"商家21","sellerid":"21"}]
*/
private
string msg;
private
string code;
private
list<databean> data;
public
string getmsg() {
return
msg;
}
public
void
setmsg(string msg) {
this
.msg = msg;
}
public
string getcode() {
return
code;
}
public
void
setcode(string code) {
this
.code = code;
}
public
list<databean> getdata() {
return
data;
}
public
void
setdata(list<databean> data) {
this
.data = data;
}
public
static
class
databean {
/**
* list : [{"bargainprice":22.9,"createtime":"2017-10-14t21:48:08","detailurl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=qqfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fnbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cn33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035n33857877.jpg!q70.jpg","num":1,"pid":24,"price":288,"pscid":2,"selected":0,"sellerid":1,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"},{"bargainprice":11800,"createtime":"2017-10-10t17:33:37","detailurl":"https://item.m.jd.com/product/4338107.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=qqfriends","images":"https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5nc3a7dab5.jpg!q70.jpg","num":2,"pid":57,"price":5199,"pscid":40,"selected":0,"sellerid":1,"subhead":"【i5 mx150 2g显存】全高清窄边框 8g内存 256固态硬盘 支持指纹识别 预装win10系统","title":"小米(mi)air 13.3英寸全金属轻薄笔记本(i5-7200u 8g 256g pcle ssd mx150 2g独显 fhd 指纹识别 win10)银 "},{"bargainprice":99,"createtime":"2017-10-14t21:38:26","detailurl":"https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=qqfriends","images":"https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12n5b900606.jpg!q70.jpg","num":1,"pid":45,"price":2999,"pscid":39,"selected":0,"sellerid":1,"subhead":"高清双摄,就是清晰!2000+1600万高清摄像头,6gb大内存+高通骁龙835处理器,性能怪兽!","title":"一加手机5 (a5000) 6gb+64gb 月岩灰 全网通 双卡双待 移动联通电信4g手机"}]
* sellername : 商家1
* sellerid : 1
*/
private
string sellername;
private
string sellerid;
private
list<listbean> list;
private
boolean
check;
public
boolean
ischeck() {
return
check;
}
public
void
setcheck(
boolean
check) {
this
.check = check;
}
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 : 1
* 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;
private
int
cou=
1
;
public
int
getcou() {
return
cou;
}
public
void
setcou(
int
cou) {
this
.cou = cou;
}
private
boolean
check;
public
boolean
ischeck() {
return
check;
}
public
void
setcheck(
boolean
check) {
this
.check = check;
}
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;
}
}
}
}
|
app 。
1
2
3
4
5
6
7
8
|
public
class
myapp
extends
application{
@override
public
void
oncreate() {
super
.oncreate();
fresco.initialize(
this
);
}
}
|
view层 。
先写两个接口 。
1
2
3
|
public
interface
icart {
void
showlist(list<cartbean.databean> grouplist, list<list<cartbean.databean.listbean>> childlist);
}
|
1
2
3
4
|
public
interface
iview<t> {
void
showbean(t t);
void
showstr(string s);
}
|
主页面布局 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
<?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.bwie.zhangzhen20170108.mainactivity"
>
<expandablelistview
android:id=
"@+id/elv"
android:layout_weight=
"1"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<linearlayout
android:layout_weight=
"9"
android:orientation=
"horizontal"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<checkbox
android:id=
"@+id/quanxuan"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<textview
android:text=
"全选"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<linearlayout
android:layout_marginleft=
"50dp"
android:orientation=
"vertical"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
>
<textview
android:id=
"@+id/zongjia"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"总价:0.0"
/>
<textview
android:text=
"共0件商品"
android:id=
"@+id/tv_count"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</linearlayout>
<textview
android:text=
"去结算"
android:background=
"#ffd82020"
android:layout_marginleft=
"100dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</linearlayout>
</linearlayout>
|
主页面 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
public
class
mainactivity
extends
appcompatactivity
implements
icart {
private
expandablelistview melv;
private
checkbox mquanxuan;
private
textview mzongjia;
private
textview mtvcount;
private
myexpandableadapter myexpandableadapter;
@override
protected
void
oncreate(bundle savedinstancestate) {
super
.oncreate(savedinstancestate);
setcontentview(r.layout.activity_main);
initview();
new
cartpresenter(
this
).getcart();
eventbus.getdefault().register(
this
);
mquanxuan.setonclicklistener(
new
view.onclicklistener() {
@override
public
void
onclick(view v) {
myexpandableadapter.qx(mquanxuan.ischecked());
}
});
}
private
void
initview() {
melv = (expandablelistview) findviewbyid(r.id.elv);
mquanxuan = (checkbox) findviewbyid(r.id.quanxuan);
mzongjia = (textview) findviewbyid(r.id.zongjia);
mtvcount = (textview) findviewbyid(r.id.tv_count);
}
@override
public
void
showlist(list<cartbean.databean> grouplist, list<list<cartbean.databean.listbean>> childlist) {
myexpandableadapter =
new
myexpandableadapter(grouplist,
this
,childlist);
melv.setadapter(myexpandableadapter);
for
(
int
i =
0
; i <grouplist.size() ; i++) {
melv.expandgroup(i);
}
}
//接收传过来的值
@subscribe
public
void
onpriceandcount(countandprice cp){
mzongjia.settext(
"共"
+cp.getcount()+
"件商品"
);
mtvcount.settext(
"总计:"
+cp.getprice());
}
//接收传过来的值
@subscribe
public
void
onpriceandcount1(messgeevent event){
//改变全选的状态
mquanxuan.setchecked(event.ischeck());
}
@override
protected
void
ondestroy() {
super
.ondestroy();
eventbus.getdefault().unregister(
this
);
}
}
|
第二个页面布局 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<linearlayout xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
android:id=
"@+id/activity_add"
tools:context=
"com.bwie.zhangzhen20170108.addactivity"
>
<com.facebook.drawee.view.simpledraweeview
android:layout_width=
"300dp"
android:id=
"@+id/xqsdv1"
android:layout_gravity=
"center"
android:layout_height=
"300dp"
/>
<textview
android:id=
"@+id/tvtitle1"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
<linearlayout
android:orientation=
"horizontal"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<button
android:id=
"@+id/tiaozhuan1"
android:layout_weight=
"1"
android:text=
"跳转到购物车"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
<button
android:id=
"@+id/tianjia1"
android:layout_weight=
"1"
android:text=
"添加到购物车"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
</linearlayout>
</linearlayout>
|
实现购物车的代码 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
public
class
addactivity
extends
appcompatactivity
implements
view.onclicklistener,iview {
private
simpledraweeview mxqsdv;
private
textview mtvtitle;
private
button mtiaozhuan;
private
button mtianjia;
private
linearlayout maddactivity;
private
xqpresenter xqpresenter;
@override
protected
void
oncreate(bundle savedinstancestate) {
super
.oncreate(savedinstancestate);
setcontentview(r.layout.activity_add);
initview();
xqpresenter=
new
xqpresenter(
this
);
xqpresenter.getxq();
}
private
void
initview() {
mxqsdv = (simpledraweeview) findviewbyid(r.id.xqsdv1);
mtvtitle = (textview) findviewbyid(r.id.tvtitle1);
mtiaozhuan = (button) findviewbyid(r.id.tiaozhuan1);
mtiaozhuan.setonclicklistener(
this
);
mtianjia = (button) findviewbyid(r.id.tianjia1);
mtianjia.setonclicklistener(
this
);
maddactivity = (linearlayout) findviewbyid(r.id.activity_add);
}
@override
public
void
onclick(view v) {
switch
(v.getid()) {
default
:
break
;
//跳到mainactivity (购物车)
case
r.id.tiaozhuan1:
startactivity(
new
intent(
this
,mainactivity.
class
));
break
;
case
r.id.tianjia1:
xqpresenter.getadd();
break
;
}
}
@override
public
void
showbean(object o) {
xqbean xqbean = (xqbean) o;
xqbean.databean data = xqbean.getdata();
string s = data.getimages().split(
"|"
)[
0
];
uri uri =uri.parse(s);
//地址转换成uri
mxqsdv.setimageuri(uri);
mtvtitle.settext(data.gettitle()+
" "
+data.getprice());
}
@override
public
void
showstr(string s) {
toast.maketext(
this
, s, toast.length_short).show();
}
}
|
eventbus包 。
设置一个数量和价格的类 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public
class
countandprice {
private
int
count ;
private
int
price;
public
int
getcount() {
return
count;
}
public
void
setcount(
int
count) {
this
.count = count;
}
public
int
getprice() {
return
price;
}
public
void
setprice(
int
price) {
this
.price = price;
}
}
|
eventbus 。
1
2
3
4
5
6
7
8
9
10
11
|
public
class
messgeevent {
private
boolean
check;
public
boolean
ischeck() {
return
check;
}
public
void
setcheck(
boolean
check) {
this
.check = check;
}
}
|
model 。
实现详情页model层的接口 。
1
2
3
|
public
interface
ixqmodel {
public
void
getxq(
int
pid, string str,
final
onnetlisenter<xqbean> cgsb);
}
|
实现详情页model 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
public
class
xqmodel
implements
ixqmodel{
@override
public
void
getxq(
int
pid, string str,
final
onnetlisenter<xqbean> onnetlisenter) {
flowable<xqbean> flowable = retrofithepler.getserviceapi().getxq(pid, str);
flowable.observeon(androidschedulers.mainthread())
.subscribeon(schedulers.io())
.subscribe(
new
consumer<xqbean>() {
@override
public
void
accept(xqbean xqbean)
throws
exception {
onnetlisenter.success(xqbean);
}
});
}
public
void
getadd(
int
uid,
int
pid, string str,
final
onnetlisenter<addcart> onnetlisenter){
flowable<addcart> flowable = retrofithepler.getserviceapi().getmsg(uid, pid, str);
flowable.observeon(androidschedulers.mainthread())
.subscribeon(schedulers.io())
.subscribe(
new
consumer<addcart>() {
@override
public
void
accept(addcart addcart)
throws
exception {
onnetlisenter.success(addcart);
}
});
}
}
|
购物车的model 。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
public
class
cartmodel {
public
void
getcart(
int
uid, string str,
final
onnetlisenter<cartbean> onnetlisenter){
flowable<cartbean> flowable = retrofithepler.getserviceapi().getcart(uid,str);
flowable.observeon(androidschedulers.mainthread())
.subscribeon(schedulers.io())
.subscribe(
new
consumer<cartbean>() {
@override
public
void
accept(cartbean cartbean)
throws
exception {
onnetlisenter.success(cartbean);
}
});
}
}
|
presenter层 。
详情页的p层 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
public
class
xqpresenter {
private
final
xqmodel xqmodel;
private
iview iview;
public
xqpresenter(iview iview) {
xqmodel =
new
xqmodel();
this
.iview=iview;
}
public
void
getxq(){
xqmodel.getxq(
12
,
"android"
,
new
onnetlisenter<xqbean>() {
@override
public
void
success(xqbean xqbean) {
iview.showbean(xqbean);
}
});
}
public
void
getadd(){
xqmodel.getadd(
3043
,
12
,
"android"
,
new
onnetlisenter<addcart>() {
@override
public
void
success(addcart addcart) {
iview.showstr(addcart.getmsg());
}
});
}
}
|
购物车的p层 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
public
class
cartpresenter {
private
icart icart;
private
final
cartmodel cartmodel;
public
cartpresenter(icart icart) {
this
.icart = icart;
cartmodel =
new
cartmodel();
}
public
void
getcart(){
cartmodel.getcart(
3043
,
"android"
,
new
onnetlisenter<cartbean>(){
@override
public
void
success(cartbean cartbean) {
list<cartbean.databean> grouplist = cartbean.getdata();
list<list<cartbean.databean.listbean>> childlist =
new
arraylist<>();
for
(
int
i =
0
; i < grouplist.size(); i++) {
cartbean.databean databean = grouplist.get(i);
list<cartbean.databean.listbean> list = databean.getlist();
childlist.add(list);
}
icart.showlist(grouplist,childlist);
}
});
}
}
|
adapter 。
public class myexpandableadapter extends baseexpandablelistadapter { 。
private list<cartbean.databean> groupdata; private context context; private list<list<cartbean.databean.listbean>> childlist,
public myexpandableadapter( list<cartbean.databean> groupdata, context context, list<list<cartbean.databean.listbean>> childlist) { this.groupdata = groupdata; this.context = context; this.childlist = childlist; } 。
@ override public int getgroupcount() { return groupdata.size(); } 。
@ override public int getchildrencount(int groupposition) { return childlist.get(groupposition).size(); } 。
@override public object getgroup(int groupposition) { return groupdata.get(groupposition); } 。
@override public object getchild(int groupposition, int childposition) { return null; } 。
@override public long getgroupid(int groupposition) { return groupposition; } 。
@override public long getchildid(int groupposition, int childposition) { return childposition; } 。
@override public boolean hasstableids() { return false; } 。
@override public view getgroupview(final int groupposition, boolean isexpanded, view convertview, viewgroup parent) { final groupviewholder holder; if (convertview == null) { convertview = view.inflate(context, r.layout.group_item, null); holder = new groupviewholder(); holder.tv_group = (textview) convertview.findviewbyid(r.id.tv_group); holder.group_cb = (checkbox) convertview.findviewbyid(r.id.gx_group),
convertview.settag(holder); } else { holder = (groupviewholder) convertview.gettag(); } final cartbean.databean databean = groupdata.get(groupposition),
string sellername = databean.getsellername(); holder.group_cb.setchecked(databean.ischeck()); //点击一级checkbox的状态 holder.group_cb.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { databean.setcheck(holder.group_cb.ischecked()); //改变所有孩子的状态 changechildstate(groupposition,holder.group_cb.ischecked()); eventbus.getdefault().post(js()); //通过判断一级的checkbox判断全选的状态 changemianqxstatus(checkgroupall()); notifydatasetchanged(); } }),
return convertview; } 。
@override public view getchildview(final int groupposition, final int childposition, boolean islastchild, view convertview, viewgroup parent) { final childviewholder holder; if (convertview == null) { convertview = view.inflate(context, r.layout.child_item, null); holder = new childviewholder(),
holder.tv_title= (textview) convertview.findviewbyid(r.id.title); holder.price= (textview) convertview.findviewbyid(r.id.price); holder.child_cb= (checkbox) convertview.findviewbyid(r.id.gouxuan_child); holder.add= (textview) convertview.findviewbyid(r.id.jia); holder.del= (textview) convertview.findviewbyid(r.id.del); holder.jian= (textview) convertview.findviewbyid(r.id.jian); holder.sdv= (simpledraweeview) convertview.findviewbyid(r.id.title_img); holder.tv_num= (textview) convertview.findviewbyid(r.id.tv_num); holder.yanse= (textview) convertview.findviewbyid(r.id.yanse); convertview.settag(holder); } else { holder = (childviewholder) convertview.gettag(); } final cartbean.databean.listbean listbean = childlist.get(groupposition).get(childposition); int price = (int) listbean.getprice(); holder.child_cb.setchecked(listbean.ischeck()); holder.tv_title.settext(title); string subhead = listbean.getsubhead(); string substring = subhead.substring(1, 10)+"....."; holder.yanse.settext(substring); string images = listbean.getimages(); string[] split = images.split("|"); string s = split[0]; uri uri=uri.parse(s); holder.sdv.setimageuri(uri); // listbean.setcou(integer.parseint(holder.tv_num.gettext().tostring())); //给子条目的checkbox点击事件 holder.child_cb.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { listbean.setcheck(holder.child_cb.ischecked()),
eventbus.getdefault().post(js()); //如果二级的checkbox选中,就让一级的checkbox勾选 if(holder.child_cb.ischecked()) { 。
if (ischeckallchild(groupposition)) { //改变一级checkbox的状态 changegroupstatus(groupposition,true); //通过判断一级的checkbox的状态来改变全选的状态 changemianqxstatus(checkgroupall()),
} }else{ changegroupstatus(groupposition,false); changemianqxstatus(checkgroupall()); } notifydatasetchanged(); } 。
}),
//点击加加的功能 holder.add.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { int cou = listbean.getcou(); holder.tv_num.settext(++cou+""); listbean.setcou(cou); if(holder.child_cb.ischecked()){ eventbus.getdefault().post(js()); } 。
} }); //点击减减的功能 holder.jian.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { int cou = listbean.getcou(),
if(cou==1) { toast.maketext(context, "最小数量为1", toast.length_short).show(); return;} holder.tv_num.settext(--cou+""); listbean.setcou(cou); if (holder.child_cb.ischecked()) { eventbus.getdefault().post(js()),
} } }); //点击删除 holder.del.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { list<cartbean.databean.listbean> listbeen = childlist.get(groupposition),
cartbean.databean.listbean remove = listbeen.remove(childposition); if(listbeen.size()==0){ childlist.remove(childposition); groupdata.remove(groupposition); } eventbus.getdefault().post(js()); notifydatasetchanged(),
} }),
return convertview; } 。
@override public boolean ischildselectable(int groupposition, int childposition) { return true; } 。
class groupviewholder { checkbox group_cb; textview tv_group; } 。
class childviewholder { checkbox child_cb; textview tv_title,price,yanse,tv_num; textview del,add,jian; simpledraweeview sdv,
} /** * 判断全部的二级是checkbox否选中 * */ private boolean ischeckallchild(int g){ list<cartbean.databean.listbean> listbeen = childlist.get(g),
for (int i = 0; i <listbeen.size() ; i++) { cartbean.databean.listbean listbean = listbeen.get(i),
if(!listbean.ischeck()){ return false; } } return true; } 。
/** * 计算数量和价格 * 通过遍历一级的得到二级的checkbox,如果是选择的选中状态的话,就统计它们的总计的数量和价格 */ private countandprice js(){ int cou=0; int jiage=0; for (int i = 0; i <groupdata.size() ; i++) { for (int j = 0; j <childlist.get(i).size() ; j++) { cartbean.databean.listbean listbean = childlist.get(i).get(j); if(listbean.ischeck()){ cou+=listbean.getcou(); jiage+=(int)listbean.getprice()*listbean.getcou(); } 。
} 。
} countandprice countandprice = new countandprice(); countandprice.setcount(cou); countandprice.setprice(jiage); return countandprice; } /** * 改变一级列表的状态 */ private void changegroupstatus(int groupposition,boolean flag ){ cartbean.databean databean = groupdata.get(groupposition),
databean.setcheck(flag); } /** * 改变全选的状态 * */ private void changemianqxstatus(boolean flag){ messgeevent messgeevent = new messgeevent(); messgeevent.setcheck(flag); eventbus.getdefault().post(messgeevent); } /** * 判断一级的是否全部选中 */ private boolean checkgroupall(){ for (int i = 0; i < groupdata.size(); i++) { if(!groupdata.get(i).ischeck()){ return false; } } return true; } /** * 改变所有孩子的状态 */ private void changechildstate(int groupistion,boolean flag){ list<cartbean.databean.listbean> listbeen = childlist.get(groupistion); for (int i = 0; i < listbeen.size(); i++) { listbeen.get(i).setcheck(flag); } } /** * 改变全选的 */ public void qx(boolean flag){ for (int i = 0; i < groupdata.size(); i++) { changegroupstatus(i, flag); changechildstate(i, flag); } eventbus.getdefault().post(js()); notifydatasetchanged(); } } 。
group_item.xml 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<?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"
>
<checkbox
android:id=
"@+id/gx_group"
android:focusable=
"false"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<textview
android:id=
"@+id/tv_group"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
</linearlayout>
|
child_item.xml 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
<?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=
"vertical"
>
<textview
android:id=
"@+id/title"
android:layout_marginleft=
"20dp"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
<linearlayout
android:orientation=
"horizontal"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
>
<checkbox
android:layout_marginleft=
"20dp"
android:gravity=
"center_vertical"
android:id=
"@+id/gouxuan_child"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<com.facebook.drawee.view.simpledraweeview
android:gravity=
"center_vertical"
android:id=
"@+id/title_img"
android:layout_width=
"50dp"
android:layout_height=
"50dp"
/>
<linearlayout
android:orientation=
"vertical"
android:layout_marginleft=
"30dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
>
<textview
android:id=
"@+id/price"
android:layout_marginleft=
"10dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<textview
android:id=
"@+id/yanse"
android:layout_marginleft=
"10dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<linearlayout
android:layout_marginleft=
"100dp"
android:orientation=
"horizontal"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
>
<textview
android:id=
"@+id/jian"
android:layout_width=
"20dp"
android:layout_height=
"20dp"
android:textsize=
"15sp"
android:text=
"一"
/>
<textview
android:id=
"@+id/tv_num"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginleft=
"5dp"
android:paddingbottom=
"2dp"
android:paddingleft=
"20dp"
android:paddingright=
"20dp"
android:paddingtop=
"2dp"
android:text=
"1"
/>
<textview
android:id=
"@+id/jia"
android:layout_width=
"20dp"
android:layout_height=
"20dp"
android:layout_marginleft=
"5dp"
android:text=
"+"
android:textsize=
"15sp"
/>
</linearlayout>
</linearlayout>
<textview
android:id=
"@+id/del"
android:layout_marginleft=
"20dp"
android:text=
"删除"
android:textcolor=
"#ffffff"
android:background=
"#ff3660"
android:layout_width=
"32dp"
android:layout_height=
"29dp"
/>
</linearlayout>
</linearlayout>
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:https://blog.csdn.net/Cyq_0927/article/details/79006812 。
最后此篇关于RxJava+Retrofit+Mvp实现购物车的文章就讲到这里了,如果你想了解更多关于RxJava+Retrofit+Mvp实现购物车的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我相信 Presenter 是负责处理 MVP 应用程序导航方面的人。这是真的还是有异常(exception)? 最佳答案 我认为 View 是唯一负责屏幕导航的 View 。 Here我们对这个“A
我看到了两种实现“加载”反馈的基本方法(例如旋转加载图标): 在演示者中: void displayData() { display.startShowingLoadingIcon();
我有一个方法,用户可以搜索文章编号,如果它在数据库中可用,则文章编号绑定(bind)到 BindingList。现在我想让用户知道该文章是否在数据库中不可用。我该如何以正确的方式做到这一点? 只需将消
我们正在使用 gwt-presenter,但并不是一个特定于此的问题...... 我有一张包含用户的表格。当我在 View 中构建表格时(根据演示者提供的数据),我需要在行的末尾添加两个操作按钮(“编
请用一个简单的例子来描述MVP-Passive View和MVP-Supervising controller的区别。最好显示如何使用 mvp 技术(被动 View 和监督 Controller )绑
GWT 2.1 包含一个 MVP framework其中包括 Google 的 Ray Ryan 在 Google I/O 2009 上概述的 PlaceService 实现。 那个talk启发了一些
在Model-View-Presenter模式中,我们应该在哪里编写用户输入的验证。 最佳答案 Realm 特定的规则/验证应在模型中。您可以使用model.validate()来告知您是否违反规则。
当我们在面试的时候被问到谈谈你对MVC,MVP,MVVM的理解。我们该如何回答,下面我们将对这些模式进行总结。 一、web1.0时代 在web1.0时代,当时并没有前端这个概念,当时如果要开发一个项目
我正在寻找有关 GWT 架构的指南 - 何时使用自包含小部件与 MVP/事件/场所。 背景 阅读了 Google 文档并搜索了 Stackoverflow,gwt-examples 项目为这个问题提供
在地点更改时更新事件状态的最佳做法是什么?假设您有一个带有 View 的事件,该 View 显示类别列表和类别中的项目列表。如果选择了不同的类别,则应用程序会使用类别 ID 转到新位置。然后我只想刷新
在 GWT 中使用 MVP 时,您将如何使用表?例如,如果您有一个用户表,您的 View 看起来像这样吗? public interface MyDisplay{ HasValue users();
我有一个 GWT 应用程序,我正在将 GWT MVP 与地点/事件一起使用。 我的应用程序布局类似于 菜单 |内容 菜单和内容显示将动态变化,其中一个单独变化。我的意思是,当内容显示更改时,我不想更新
我正在使用 Windows 窗体实现 MVP 模式,我对当前的实现有疑问,因为我正试图将其融入更复杂的架构中。 现在我有一个带有属性的完全不可知的 View ,一个在构造函数中注入(inject) V
对所有 GWT 大师的问题。 我是 GWT 的新手,正在尝试了解编写 GWT 应用程序的最佳实践。我经历过"Large scale application development and MVP"基于
我最近一直试图从架构的角度来理解 MVP 架构中交互器和用例之间的关系。我的疑问是关于部件之间的通信以及符合 MVP 标准的内容。 问题是我见过很多相互矛盾的流程图。其中一些似乎每个演示者都有一个交互
我有一个具有 MVP 架构模式的应用程序。 现在,我正在尝试在我的应用程序中实现 Livedata。 我搜索了很多,但我找不到任何教程或示例。 所有教程都说实时数据适用于 MVVM 模式。 在 MVP
我有一个关于在使用 MVP 时如何处理演示者之间的通信的问题。假设我有两个 MVP-triads。一个是产品列表(Triad A),另一个是有关当前所选产品的一般信息(Triad B)。 我如何告诉
我主要具有 ASP.Net 背景,并具有一些 MVC 知识。我也做了一些 Silverlight 和 MVVM,但是我现在即将转向 Winforms,我对它的经验很少,所以我想知道如何处理 MVP。
我读了鲍勃叔叔的《整洁架构书》。我尝试实现简单的例子。我有这个图: 我不明白如何实现红线部分。例如,我有一个简单的网页: 我有 2 个按钮、一个已编辑的文本和一个标签。如果我按下发送到服务器按钮 -
我正在查看 MVP 的 google 示例,我看到 this作为 Activity 的 onCreate 中的最后一个语句: new TaskDetailPresenter(
我是一名优秀的程序员,十分优秀!