- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Rxjava+Retrofit+MVP实现购物车功能由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家分享了rxjava retrofit实现购物车的具体代码,供大家参考,具体内容如下 。
效果图:
1.依赖 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
annotationprocessor
'com.jakewharton:butterknife-compiler:8.8.1'
compile
'com.jakewharton:butterknife:8.8.1'
compile
'com.android.support:recyclerview-v7:26.0.0-alpha1'
compile
'com.squareup.retrofit2:retrofit:2.3.0'
compile
'com.squareup.retrofit2:converter-gson:2.3.0'
compile
'com.facebook.fresco:fresco:0.12.0'
compile
'com.facebook.fresco:animated-base-support:0.12.0'
compile
'com.facebook.fresco:animated-webp:0.12.0'
compile
'com.facebook.fresco:webpsupport:0.12.0'
compile
'io.reactivex.rxjava2:rxjava:2.1.7'
compile
'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile
'io.reactivex.rxjava2:rxandroid:2.0.1'
compile
'com.squareup.okhttp3:okhttp:3.9.0'
compile
'com.google.code.gson:gson:2.8.1'
|
2.布局 。
1.加减器布局 layout_add_delete 。
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
|
<?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=
"30dp"
android:layout_height=
"30dp"
android:text=
"减"
android:gravity=
"center"
android:background=
"#8b948b"
/>
<edittext
android:id=
"@+id/et_number"
android:layout_margintop=
"2dp"
android:layout_width=
"50dp"
android:layout_height=
"30dp"
android:background=
"@drawable/edit"
android:layout_weight=
"0.00"
android:gravity=
"center"
android:text=
"1"
/>
<textview
android:id=
"@+id/txt_add"
android:layout_width=
"30dp"
android:layout_height=
"30dp"
android:text=
"加"
android:gravity=
"center"
android:background=
"#8b948b"
/>
</linearlayout>
|
2. 商品详情布局 activity_main 。
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
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<relativelayout xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:fresco=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<linearlayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
>
<com.facebook.drawee.view.simpledraweeview
android:id=
"@+id/my_image_view"
android:layout_width=
"match_parent"
android:layout_height=
"450dp"
fresco:placeholderimage=
"@mipmap/ic_launcher"
/>
<textview
android:id=
"@+id/goods_title"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"10dp"
android:text=
"a啊啊是你的"
android:textsize=
"20dp"
/>
<textview
android:id=
"@+id/goods_price"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"10dp"
android:text=
"¥ 18132"
android:textcolor=
"#dc5f2e"
android:textsize=
"18dp"
/>
<textview
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"10dp"
android:text=
"我是商家19"
android:textsize=
"16dp"
/>
</linearlayout>
<linearlayout
android:layout_alignparentbottom=
"true"
android:layout_width=
"match_parent"
android:layout_height=
"50dp"
android:orientation=
"horizontal"
>
<button
android:id=
"@+id/btn_addcart"
android:layout_weight=
"1"
android:layout_width=
"0dp"
android:layout_height=
"match_parent"
android:background=
"#ffc207"
android:text=
"加入购物车"
/>
<button
android:id=
"@+id/btn_shopping"
android:layout_weight=
"1"
android:layout_width=
"0dp"
android:layout_height=
"match_parent"
android:background=
"#ff6b06"
android:text=
"立即购买"
/>
</linearlayout>
</relativelayout>
|
3.购物车布局 activity_main2 。
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
|
<?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"
>
<!--头布局-->
<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"
android:src=
"@drawable/back"
/>
<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_marginleft=
"20dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<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:orientation=
"vertical"
android:layout_marginright=
"20dp"
android:layout_weight=
"1"
>
<linearlayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:gravity=
"right"
>
<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:text=
"共有商品:0件"
android:gravity=
"right"
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"
/>
<textview
android:id=
"@+id/tv_go_to_del"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_weight=
"3"
android:background=
"#e2231c"
android:clickable=
"true"
android:gravity=
"center"
android:text=
"删除"
android:textcolor=
"#fafafa"
android:visibility=
"gone"
/>
</linearlayout>
</linearlayout>
</linearlayout>
|
4.二级列表组级布局 ex_group_item 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<?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_marginleft=
"20dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:focusable=
"false"
/>
<textview
android:id=
"@+id/shop_name"
android:layout_marginleft=
"20dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textsize=
"16dp"
/>
</linearlayout>
|
5.二级列表子布局 ex_child_item 。
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
|
<?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:fresco=
"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_margintop=
"50dp"
android:layout_marginleft=
"20dp"
android:layout_marginbottom=
"50dp"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<relativelayout
android:layout_marginleft=
"20dp"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<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_marginleft=
"17dp"
android:layout_marginstart=
"17dp"
android:text=
"textview"
android:layout_alignparenttop=
"true"
/>
<!--<imageview
android:id=
"@+id/shop_img"
android:layout_width=
"90dp"
android:layout_height=
"90dp"
android:layout_margintop=
"30dp"
app:srccompat=
"@mipmap/ic_launcher"
android:layout_below=
"@+id/shop_name"
android:layout_alignparentleft=
"true"
android:layout_alignparentstart=
"true"
/>-->
<com.facebook.drawee.view.simpledraweeview
android:id=
"@+id/shop_img"
android:layout_width=
"90dp"
android:layout_height=
"90dp"
android:layout_margintop=
"30dp"
fresco:placeholderimage=
"@mipmap/ic_launcher"
android:layout_below=
"@+id/shop_name"
android:layout_alignparentleft=
"true"
android:layout_alignparentstart=
"true"
/>
<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.bwei.gepeng.myview.adddeleteview
android:id=
"@+id/adv"
android:layout_width=
"160dp"
android:layout_height=
"30dp"
android:layout_below=
"@+id/shop_price"
android:layout_margintop=
"30dp"
android:layout_marginleft=
"140dp"
app:left_text=
"-"
app:right_text=
"+"
app:middle_text=
"1"
android:focusable=
"false"
>
</com.bwei.gepeng.myview.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:visibility=
"invisible"
android:text=
"删除"
/>
</relativelayout>
</linearlayout>
|
3.实体类 。
1. messagebean 。
。
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
|
package
com.bwei.gepeng.entity;
public
class
messagebean <t>{
private
string code;
private
t data;
private
string msg;
private
sellerbean seller;
public
string getcode() {
return
code;
}
public
void
setcode(string code) {
this
.code = code;
}
public
t getdata() {
return
data;
}
public
void
setdata(t data) {
this
.data = 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
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;
}
}
}
|
2.goodsshowbean 。
package com.bwei.gepeng.entity; public class goodsshowbean { 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; } 。
3. cartbean 。
。
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
|
package
com.bwei.gepeng.entity;
import
java.util.list;
public
class
cartbean {
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 {
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;
}
}
@override
public
string tostring() {
return
"cartbean{"
+
"sellername='"
+ sellername + '
''
+
", sellerid='"
+ sellerid + '
''
+
", list="
+ list +
'}'
;
}
}
|
4. groupbean 。
。
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
|
package
com.bwei.gepeng.entity;
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 +
'}'
;
}
}
|
5.childbean 。
。
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
|
package
com.bwei.gepeng.entity;
public
class
childbean {
private
string title;
private
string images;
private
double
price;
private
int
num;
private
boolean
childcb;
private
boolean
btn;
private
int
pid;
public
childbean(string title, string images,
double
price,
int
num,
boolean
childcb,
boolean
btn,
int
pid) {
this
.title = title;
this
.images = images;
this
.price = price;
this
.num = num;
this
.childcb = childcb;
this
.btn = btn;
this
.pid = pid;
}
public
int
getpid() {
return
pid;
}
public
void
setpid(
int
pid) {
this
.pid = pid;
}
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 +
", btn="
+ btn +
", pid="
+ pid +
'}'
;
}
}
|
4.接口 。
1.apiservice 。
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
|
package
com.bwei.gepeng.http;
import
com.bwei.gepeng.entity.cartbean;
import
com.bwei.gepeng.entity.goodsshowbean;
import
com.bwei.gepeng.entity.messagebean;
import
java.util.list;
import
java.util.map;
import
io.reactivex.flowable;
import
retrofit2.http.get;
import
retrofit2.http.querymap;
public
interface
apiservice {
//查询商品详情75
//http://120.27.23.105/product/getproductdetail?pid=75&source=android
@get
(
"product/getproductdetail"
)
flowable<messagebean<goodsshowbean>> getnews(
@querymap
map<string,string> map);
//查询购物车
//http://120.27.23.105/product/getcarts?uid=3802&source=android
@get
(
"product/getcarts"
)
flowable<messagebean<list<cartbean>>> getcart(
@querymap
map<string,string> map);
//删除购物车
//http://120.27.23.105/product/getcarts?uid=3802&source=android
@get
(
"product/deletecart"
)
flowable<messagebean<list<cartbean>>> getdel(
@querymap
map<string,string> map);
//添加购物车
//http://120.27.23.105/product/addcart?uid=3802&pid=75&source=android
@get
(
"product/addcart"
)
flowable<messagebean<list<cartbean>>> getadd(
@querymap
map<string,string> map);
}
2
.iview
[java] view plain copy
public
interface
iview {
void
onsuccess(object o,string tag);
void
onfailed(exception e,string tag);
}
3
.ipresenter
[java] view plain copy
import
java.util.map;
public
interface
ipresenter {
void
getdata(map<string,string> map, string tag);
}
4
.imodel
[java] view plain copy
import
java.util.map;
public
interface
imodel {
void
getdata(map<string,string> map,string tag);
}
|
5.代码 。
1.自定义view 加减器 adddeleteview 。
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
|
package
com.bwei.gepeng.myview;
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;
import
com.bwei.gepeng.r;
public
class
adddeleteview
extends
linearlayout {
private
onadddelclicklistener listener;
private
edittext etnumber;
//对外提供一个点击的回调接口
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
);
//获取控件
textview txtdelete=findviewbyid(r.id.txt_delete);
textview 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.red);
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;
}
}
|
2.retrofit工具类 retrofitutils 。
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
|
package
com.bwei.gepeng.http;
import
java.io.ioexception;
import
okhttp3.httpurl;
import
okhttp3.interceptor;
import
okhttp3.okhttpclient;
import
okhttp3.request;
import
okhttp3.response;
import
retrofit2.retrofit;
import
retrofit2.adapter.rxjava2.rxjava2calladapterfactory;
import
retrofit2.converter.gson.gsonconverterfactory;
public
class
retrofitutils {
private
static
volatile
retrofitutils instance;
private
final
retrofit retrofit;
private
retrofitutils(){
okhttpclient client =
new
okhttpclient.builder().addinterceptor(
new
logger()).build();
retrofit =
new
retrofit.builder()
.client(client)
.addcalladapterfactory(rxjava2calladapterfactory.create())
.addconverterfactory(gsonconverterfactory.create())
.baseurl(
"http://120.27.23.105/"
)
.build();
}
public
static
retrofitutils getinstance(){
if
(instance==
null
){
synchronized
(retrofitutils.
class
){
if
(instance==
null
){
instance=
new
retrofitutils();
}
}
}
return
instance;
}
public
apiservice getapiservice(){
apiservice apiservice = retrofit.create(apiservice.
class
);
return
apiservice;
}
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);
}
}
}
|
3.m层 。
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
|
package
com.bwei.gepeng.model;
import
com.bwei.gepeng.entity.cartbean;
import
com.bwei.gepeng.entity.goodsshowbean;
import
com.bwei.gepeng.entity.messagebean;
import
com.bwei.gepeng.http.retrofitutils;
import
com.bwei.gepeng.presenter.newspresenter;
import
java.util.list;
import
java.util.map;
import
io.reactivex.flowable;
public
class
model
implements
imodel{
private
newspresenter presenter;
public
model(newspresenter presenter) {
this
.presenter = presenter;
}
@override
public
void
getdata(map<string, string> map, string tag) {
if
(tag.equals(
"cart"
)){
flowable<messagebean<list<cartbean>>> flowable = retrofitutils.getinstance().getapiservice().getcart(map);
presenter.get2(flowable,tag);
}
else
if
(tag.equals(
"goods"
)){
flowable<messagebean<goodsshowbean>> flowable = retrofitutils.getinstance().getapiservice().getnews(map);
presenter.get(flowable,tag);
}
else
if
(tag.equals(
"del"
)){
flowable<messagebean<list<cartbean>>> flowable = retrofitutils.getinstance().getapiservice().getdel(map);
presenter.get3(flowable,tag);
}
else
if
(tag.equals(
"add"
)){
flowable<messagebean<list<cartbean>>> flowable = retrofitutils.getinstance().getapiservice().getadd(map);
presenter.get4(flowable,tag);
}
}
}
|
4.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
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
|
package
com.bwei.gepeng.presenter;
import
com.bwei.gepeng.entity.cartbean;
import
com.bwei.gepeng.entity.goodsshowbean;
import
com.bwei.gepeng.entity.messagebean;
import
com.bwei.gepeng.model.model;
import
com.bwei.gepeng.view.iview;
import
java.util.list;
import
java.util.map;
import
io.reactivex.flowable;
import
io.reactivex.android.schedulers.androidschedulers;
import
io.reactivex.schedulers.schedulers;
import
io.reactivex.subscribers.disposablesubscriber;
public
class
newspresenter
implements
ipresenter{
private
iview iview;
private
disposablesubscriber<messagebean<goodsshowbean>> subscriber;
private
disposablesubscriber<messagebean<list<cartbean>>> subscriber2;
private
disposablesubscriber<messagebean<list<cartbean>>> subscriber3;
private
disposablesubscriber<messagebean<list<cartbean>>> subscriber4;
public
void
attachview(iview iview){
this
.iview=iview;
}
@override
public
void
getdata(map<string, string> map, string tag) {
model model =
new
model(
this
);
model.getdata(map,tag);
}
public
void
detachview(){
if
(iview!=
null
){
iview=
null
;
}
if
(subscriber!=
null
){
if
(!subscriber.isdisposed()){
subscriber.dispose();
}
}
if
(subscriber2!=
null
){
if
(!subscriber2.isdisposed()){
subscriber2.dispose();
}
}
if
(subscriber3!=
null
){
if
(!subscriber3.isdisposed()){
subscriber3.dispose();
}
}
if
(subscriber4!=
null
){
if
(!subscriber4.isdisposed()){
subscriber4.dispose();
}
}
}
//查询购物车
public
void
get(flowable<messagebean<goodsshowbean>> flowable ,
final
string tag) {
subscriber = flowable.subscribeon(schedulers.io())
.observeon(androidschedulers.mainthread())
.subscribewith(
new
disposablesubscriber<messagebean<goodsshowbean>>() {
@override
public
void
onnext(messagebean<goodsshowbean> listmessagebean) {
if
(listmessagebean !=
null
) {
goodsshowbean data = listmessagebean.getdata();
iview.onsuccess(data,tag);
}
}
@override
public
void
onerror(throwable t) {
iview.onfailed(
new
exception(t),tag);
}
@override
public
void
oncomplete() {
}
});
}
//查询商品详情75
public
void
get2(flowable<messagebean<list<cartbean>>> flowable,
final
string tag) {
subscriber2 = flowable.subscribeon(schedulers.io())
.observeon(androidschedulers.mainthread())
.subscribewith(
new
disposablesubscriber<messagebean<list<cartbean>>>() {
@override
public
void
onnext(messagebean<list<cartbean>> list) {
if
(list !=
null
) {
list<cartbean> data = list.getdata();
if
(data!=
null
){
iview.onsuccess(data,tag);
}
}
}
@override
public
void
onerror(throwable t) {
iview.onfailed(
new
exception(t),tag);
}
@override
public
void
oncomplete() {
}
});
}
//删除购物车
public
void
get3(flowable<messagebean<list<cartbean>>> flowable,
final
string tag) {
subscriber3 = flowable.subscribeon(schedulers.io())
.observeon(androidschedulers.mainthread())
.subscribewith(
new
disposablesubscriber<messagebean<list<cartbean>>>() {
@override
public
void
onnext(messagebean<list<cartbean>> list) {
if
(list !=
null
) {
string code = list.getmsg();
iview.onsuccess(code,tag);
}
}
@override
public
void
onerror(throwable t) {
iview.onfailed(
new
exception(t),tag);
}
@override
public
void
oncomplete() {
}
});
}
//添加购物车
public
void
get4(flowable<messagebean<list<cartbean>>> flowable,
final
string tag) {
subscriber4 = flowable.subscribeon(schedulers.io())
.observeon(androidschedulers.mainthread())
.subscribewith(
new
disposablesubscriber<messagebean<list<cartbean>>>() {
@override
public
void
onnext(messagebean<list<cartbean>> list) {
if
(list !=
null
) {
string code = list.getmsg();
iview.onsuccess(code,tag);
}
}
@override
public
void
onerror(throwable t) {
iview.onfailed(
new
exception(t),tag);
}
@override
public
void
oncomplete() {
}
});
}
}
|
5.mainactivity 商品详情页面 。
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
|
package
com.bwei.gepeng.view;
import
android.content.intent;
import
android.os.bundle;
import
android.support.v7.app.appcompatactivity;
import
android.view.view;
import
android.widget.textview;
import
android.widget.toast;
import
com.bwei.gepeng.r;
import
com.bwei.gepeng.entity.goodsshowbean;
import
com.bwei.gepeng.presenter.newspresenter;
import
com.facebook.drawee.view.simpledraweeview;
import
java.util.hashmap;
import
java.util.map;
import
butterknife.bindview;
import
butterknife.butterknife;
import
butterknife.onclick;
public
class
mainactivity
extends
appcompatactivity
implements
iview {
@bindview
(r.id.my_image_view)
simpledraweeview myimageview;
@bindview
(r.id.goods_title)
textview goodstitle;
@bindview
(r.id.goods_price)
textview goodsprice;
private
newspresenter presenter;
@override
protected
void
oncreate(bundle savedinstancestate) {
super
.oncreate(savedinstancestate);
setcontentview(r.layout.activity_main);
butterknife.bind(
this
);
presenter =
new
newspresenter();
presenter.attachview(
this
);
//http://120.27.23.105/product/getproductdetail?pid=75&source=android
map<string, string> map =
new
hashmap<>();
map.put(
"pid"
,
"75"
);
presenter.getdata(map,
"goods"
);
}
@override
public
void
onsuccess(object o, string tag) {
if
(tag.equals(
"goods"
)) {
if
(o !=
null
) {
goodsshowbean data = (goodsshowbean) o;
//log.e("gp", "onsuccess: " + data.tostring());
myimageview.setimageuri(data.getimages().split(
"|"
)[
0
]);
goodstitle.settext(data.gettitle());
goodsprice.settext(
"¥ "
+data.getprice());
}
}
else
if
(tag.equals(
"add"
)){
if
(o !=
null
) {
string msg = (string) o;
toast.maketext(mainactivity.
this
, msg, toast.length_short).show();
}
}
}
@override
public
void
onfailed(exception e, string tag) {
}
@onclick
({r.id.btn_addcart, r.id.btn_shopping})
public
void
onviewclicked(view view) {
switch
(view.getid()) {
case
r.id.btn_addcart:
map<string, string> map =
new
hashmap<>();
map.put(
"uid"
,
"3802"
);
map.put(
"pid"
,
"75"
);
presenter.getdata(map,
"add"
);
//toast.maketext(mainactivity.this,"添加成功",toast.length_short).show();
break
;
case
r.id.btn_shopping:
intent intent=
new
intent(mainactivity.
this
,main2activity.
class
);
startactivity(intent);
break
;
}
}
}
|
6.二级列表适配器 expandableadapter 。
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
238
239
240
241
242
243
|
package
com.bwei.gepeng.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.textview;
import
android.widget.toast;
import
com.bwei.gepeng.r;
import
com.bwei.gepeng.entity.childbean;
import
com.bwei.gepeng.entity.groupbean;
import
com.bwei.gepeng.myview.adddeleteview;
import
com.bwei.gepeng.view.main2activity;
import
com.facebook.drawee.view.simpledraweeview;
import
java.util.arraylist;
import
java.util.list;
public
class
expandableadapter
extends
baseexpandablelistadapter {
private
context context;
private
list<groupbean> groupbeen=
new
arraylist<>();
private
list<list<childbean>> childbeen=
new
arraylist<>();
private
main2activity main;
public
expandableadapter(context context, list<groupbean> groupbeen, list<list<childbean>> childbeen) {
this
.context = context;
this
.groupbeen = groupbeen;
this
.childbeen = childbeen;
this
.main = (main2activity) context;
}
//接口回调
private
ondeletegoods ondlegoods;
public
interface
ondeletegoods{
void
ondelgoods(
int
i,
int
i1,string pid);
}
public
void
setondeletegoods(ondeletegoods ondlegoods){
this
.ondlegoods=ondlegoods;
}
@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
;
}
//一级组
@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);
//main2activity main= (main2activity) context;
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);
//draweeview.setimageuri(uri);
simpledraweeview 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());
string images = childbeen.get(i).get(i1).getimages();
//glide.with(context).load(images).into(shopimg);
shopimg.setimageuri(images);
shoptitle.settext(childbeen.get(i).get(i1).gettitle());
shopprice.settext(childbeen.get(i).get(i1).getprice()+
""
);
adv.setnumber(childbeen.get(i).get(i1).getnum());
//final main2activity main= (main2activity) context;
//控制删除按钮的显隐
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) {
ondlegoods.ondelgoods(i,i1,childbeen.get(i).get(i1).getpid()+
""
);
}
});
//加减器逻辑
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();
if
(number==
1
){
toast.maketext(context,
"用户最小数量为1"
,toast.length_short).show();
}
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();
// main2activity main= (main2activity) context;
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
;
}
}
|
7.购物车页面逻辑 main2activity 。
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
package
com.bwei.gepeng.view;
import
android.os.bundle;
import
android.support.v7.app.appcompatactivity;
import
android.view.view;
import
android.widget.checkbox;
import
android.widget.expandablelistview;
import
android.widget.textview;
import
com.bwei.gepeng.r;
import
com.bwei.gepeng.adapter.expandableadapter;
import
com.bwei.gepeng.entity.cartbean;
import
com.bwei.gepeng.entity.childbean;
import
com.bwei.gepeng.entity.groupbean;
import
com.bwei.gepeng.presenter.newspresenter;
import
java.util.arraylist;
import
java.util.hashmap;
import
java.util.list;
import
java.util.map;
import
butterknife.bindview;
import
butterknife.butterknife;
import
butterknife.onclick;
public
class
main2activity
extends
appcompatactivity
implements
iview {
@bindview
(r.id.exlistview)
expandablelistview exlistview;
@bindview
(r.id.all_chekbox)
public
checkbox allcheckbox;
@bindview
(r.id.total_price)
textview totalprice;
@bindview
(r.id.total_number)
textview totalnumber;
@bindview
(r.id.tv_go_to_pay)
textview tvgotopay;
@bindview
(r.id.tv_go_to_del)
textview tvgotodel;
private
expandableadapter expandableadapter;
private
boolean
flagedit =
true
;
private
boolean
flagdel =
false
;
private
newspresenter presenter;
list<groupbean> groupbeen =
new
arraylist<>();
list<list<childbean>> childbeen =
new
arraylist<>();
int
i;
int
i1;
@override
protected
void
oncreate(bundle savedinstancestate) {
super
.oncreate(savedinstancestate);
setcontentview(r.layout.activity_main2);
butterknife.bind(
this
);
//获取二级列表适配器
expandableadapter =
new
expandableadapter(main2activity.
this
, groupbeen, childbeen);
exlistview.setadapter(expandableadapter);
exlistview.setongroupclicklistener(
new
expandablelistview.ongroupclicklistener() {
@override
public
boolean
ongroupclick(expandablelistview expandablelistview, view view,
int
i,
long
l) {
return
true
;
}
});
presenter =
new
newspresenter();
presenter.attachview(
this
);
//http://120.27.23.105/product/getcarts?uid=3802&source=android
map<string, string> map =
new
hashmap<>();
map.put(
"uid"
,
"3802"
);
presenter.getdata(map,
"cart"
);
expandableadapter.setondeletegoods(
new
expandableadapter.ondeletegoods() {
@override
public
void
ondelgoods(
int
i,
int
i1, string pid) {
main2activity.
this
.i = i;
main2activity.
this
.i1 = i1;
map<string, string> map =
new
hashmap<>();
map.put(
"uid"
,
"3802"
);
map.put(
"pid"
, pid);
presenter.getdata(map,
"del"
);
}
});
}
@override
public
void
onsuccess(object o, string tag) {
if
(tag.equals(
"cart"
)) {
if
(o !=
null
) {
list<cartbean> data = (list<cartbean>) o;
for
(cartbean i : data) {
groupbean groupbean =
new
groupbean(i.getsellername(),
false
);
this
.groupbeen.add(groupbean);
list<cartbean.listbean> list = i.getlist();
list<childbean> ls =
new
arraylist<>();
for
(cartbean.listbean w : list) {
string[] split = w.getimages().split(
"|"
);
childbean childbean =
new
childbean(w.gettitle(), split[
0
], w.getprice(),
1
,
false
,
false
, w.getpid());
ls.add(childbean);
}
this
.childbeen.add(ls);
}
for
(
int
i =
0
; i < expandableadapter.getgroupcount(); i++) {
exlistview.expandgroup(i);
}
}
}
else
if
(tag.equals(
"del"
)) {
if
(o !=
null
) {
string msg = (string) o;
if
(
this
.i != -
1
&&
this
.i1 != -
1
) {
int
size = childbeen.get(i).size();
if
(size ==
1
) {
childbeen.remove(i);
groupbeen.remove(i);
}
else
{
childbeen.get(i).remove(i1);
}
changesum(childbeen);
this
.i = -
1
;
this
.i1 = -
1
;
if
(flagdel){
delgoods();
}
}
}
}
expandableadapter.notifydatasetchanged();
}
@override
public
void
onfailed(exception e, string tag) {
}
@onclick
({r.id.back, r.id.edit, r.id.all_chekbox,r.id.tv_go_to_del})
public
void
onviewclicked(view view) {
switch
(view.getid()) {
case
r.id.back:
finish();
break
;
case
r.id.edit:
if
(flagedit){
tvgotopay.setvisibility(view.gone);
tvgotodel.setvisibility(view.visible);
}
else
{
tvgotopay.setvisibility(view.visible);
tvgotodel.setvisibility(view.gone);
}
for
(list<childbean> i1 : childbeen) {
for
(
int
r =
0
; r < i1.size(); r++) {
i1.get(r).setbtn(flagedit);
}
}
flagedit = !flagedit;
expandableadapter.notifydatasetchanged();
break
;
case
r.id.all_chekbox:
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);
break
;
case
r.id.tv_go_to_del:
if
(childbeen.size()!=
0
){
for
(list<childbean> i1 : childbeen) {
for
(
int
r =
0
; r < i1.size(); r++) {
boolean
childcb1 = i1.get(r).ischildcb();
if
(childcb1) {
flagdel=
true
;
delgoods();
if
(allcheckbox.ischecked()){
allcheckbox.setchecked(
false
);
}
break
;
}
}
if
(flagdel){
break
;
}
}
}
//toast.maketext(main2activity.this,flagdel+"",toast.length_short).show();
break
;
}
}
//递归删除
private
void
delgoods(){
boolean
flag=
false
;
for
(
int
p=
0
;p<childbeen.size();p++) {
for
(
int
r =
0
; r < childbeen.get(p).size(); r++) {
boolean
childcb1 = childbeen.get(p).get(r).ischildcb();
if
(p==childbeen.size()-
1
&&r==childbeen.get(p).size()-
1
){
flagdel=
false
;
}
if
(childcb1) {
int
pid = childbeen.get(p).get(r).getpid();
this
.i = p;
this
.i1 = r;
map<string, string> map =
new
hashmap<>();
map.put(
"uid"
,
"3802"
);
map.put(
"pid"
, pid+
""
);
presenter.getdata(map,
"del"
);
flag=!flag;
break
;
}
}
if
(flag){
break
;
}
}
}
//计算和数量总价
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(
"¥"
+ sum);
totalnumber.settext(
"共有商品:"
+ count +
"件"
);
}
}
|
6.附 。
shape图 edit 。
1
2
3
4
5
6
7
8
|
<?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>
|
application 初始化fresco 。
1
2
3
4
5
6
7
8
9
10
|
import
android.app.application;
import
com.facebook.drawee.backends.pipeline.fresco;
public
class
app
extends
application{
@override
public
void
oncreate() {
super
.oncreate();
fresco.initialize(
this
);
}
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.
原文链接:https://blog.csdn.net/gepeng_66666/article/details/78861647 。
最后此篇关于Rxjava+Retrofit+MVP实现购物车功能的文章就讲到这里了,如果你想了解更多关于Rxjava+Retrofit+MVP实现购物车功能的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
背景: 我最近一直在使用 JPA,我为相当大的关系数据库项目生成持久层的轻松程度给我留下了深刻的印象。 我们公司使用大量非 SQL 数据库,特别是面向列的数据库。我对可能对这些数据库使用 JPA 有一
我已经在我的 maven pom 中添加了这些构建配置,因为我希望将 Apache Solr 依赖项与 Jar 捆绑在一起。否则我得到了 SolarServerException: ClassNotF
interface ITurtle { void Fight(); void EatPizza(); } interface ILeonardo : ITurtle {
我希望可用于 Java 的对象/关系映射 (ORM) 工具之一能够满足这些要求: 使用 JPA 或 native SQL 查询获取大量行并将其作为实体对象返回。 允许在行(实体)中进行迭代,并在对当前
好像没有,因为我有实现From for 的代码, 我可以转换 A到 B与 .into() , 但同样的事情不适用于 Vec .into()一个Vec . 要么我搞砸了阻止实现派生的事情,要么这不应该发
在 C# 中,如果 A 实现 IX 并且 B 继承自 A ,是否必然遵循 B 实现 IX?如果是,是因为 LSP 吗?之间有什么区别吗: 1. Interface IX; Class A : IX;
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在阅读标准haskell库的(^)的实现代码: (^) :: (Num a, Integral b) => a -> b -> a x0 ^ y0 | y0 a -> b ->a expo x0
我将把国际象棋游戏表示为 C++ 结构。我认为,最好的选择是树结构(因为在每个深度我们都有几个可能的移动)。 这是一个好的方法吗? struct TreeElement{ SomeMoveType
我正在为用户名数据库实现字符串匹配算法。我的方法采用现有的用户名数据库和用户想要的新用户名,然后检查用户名是否已被占用。如果采用该方法,则该方法应该返回带有数据库中未采用的数字的用户名。 例子: “贾
我正在尝试实现 Breadth-first search algorithm , 为了找到两个顶点之间的最短距离。我开发了一个 Queue 对象来保存和检索对象,并且我有一个二维数组来保存两个给定顶点
我目前正在 ika 中开发我的 Python 游戏,它使用 python 2.5 我决定为 AI 使用 A* 寻路。然而,我发现它对我的需要来说太慢了(3-4 个敌人可能会落后于游戏,但我想供应 4-
我正在寻找 Kademlia 的开源实现C/C++ 中的分布式哈希表。它必须是轻量级和跨平台的(win/linux/mac)。 它必须能够将信息发布到 DHT 并检索它。 最佳答案 OpenDHT是
我在一本书中读到这一行:-“当我们要求 C++ 实现运行程序时,它会通过调用此函数来实现。” 而且我想知道“C++ 实现”是什么意思或具体是什么。帮忙!? 最佳答案 “C++ 实现”是指编译器加上链接
我正在尝试使用分支定界的 C++ 实现这个背包问题。此网站上有一个 Java 版本:Implementing branch and bound for knapsack 我试图让我的 C++ 版本打印
在很多情况下,我需要在 C# 中访问合适的哈希算法,从重写 GetHashCode 到对数据执行快速比较/查找。 我发现 FNV 哈希是一种非常简单/好/快速的哈希算法。但是,我从未见过 C# 实现的
目录 LRU缓存替换策略 核心思想 不适用场景 算法基本实现 算法优化
1. 绪论 在前面文章中提到 空间直角坐标系相互转换 ,测绘坐标转换时,一般涉及到的情况是:两个直角坐标系的小角度转换。这个就是我们经常在测绘数据处理中,WGS-84坐标系、54北京坐标系
在软件开发过程中,有时候我们需要定时地检查数据库中的数据,并在发现新增数据时触发一个动作。为了实现这个需求,我们在 .Net 7 下进行一次简单的演示. PeriodicTimer .
二分查找 二分查找算法,说白了就是在有序的数组里面给予一个存在数组里面的值key,然后将其先和数组中间的比较,如果key大于中间值,进行下一次mid后面的比较,直到找到相等的,就可以得到它的位置。
我是一名优秀的程序员,十分优秀!