이 기사에서는 RXJAVA RETROFIT 구현 구현 쇼핑 카트 디스플레이에 대한 특정 코드를 공유합니다. 특정 내용은 다음과 같습니다
모든 사람에게 먼저 렌더링을 보여줍니다
프레임 워크 구조 :
1. 프로젝트 프레임 워크 : MVP, 이미지 로딩은 Fresco에 의해 수행되며 Okhttp+Retrofit (직접 캡슐화, 싱글 톤 모드 추가)를 사용하여 네트워크 요청이 구현됩니다.
2. 쇼핑 카트 데이터 추가 완료 (인터페이스에 데이터가 없으면 인터페이스 도구를 사용하여 데이터를 추가 할 수 있음).
3. 뷰를 사용자 정의하여 추가 및 뺄셈 버튼을 구현하십시오. 추가 및 빼기를 클릭 할 때마다 품목의 총 수와 총 가격은 그에 따라 변경되어야합니다.
4. 수량이 1이면 마이너스 부호를 클릭하면 수량이 변경되지 않은 상태로 유지되며 토스트는 최소 수가 1이라고 사용자에게 프롬프트합니다.
5. 맨 아래의 총 수와 총 가격은 모든 품목 품목의 총 가격과 총 수입니다. 각 품목의 수량 가격이 변경되면 하단의 총 가격의 총 수를 연결해야합니다.
6. 단일 선택 리버스 선택 ALL의 기능을 구현하고, 기본 선택을 처음으로 입력하십시오. 항목을 선택하지 않은 경우 총 수와 총 가격이 하단 데이터에 포함되지 않습니다. 선택한 상태가 변경되면 바닥의 총 수와 총 가격을 올바르게 수정할 수 있습니다.
7. 삭제 버튼을 클릭하여 항목을 삭제합니다. 하단의 총 수와 총 가격을 올바르게 수정할 수 있으며 인터페이스 데이터가 삭제됩니다.
필요한 종속성 및 네트워킹 권한을 추가하십시오
컴파일 'com.squareup.retrofit2 : retrofit : 2.0.0-beta4'// retrofit2 필수 패키지 컴파일 'com.squareup.retrofit2 : 컨버터 gson : 2.0.0-beta4'// converterfactory의 gson gson packiple 'com.squareup.retrofit2 : 2.0.0-beta4'//0.0-beta4 '// 문자열 종속성 패키지 컴파일 'io.reactivex.rxjava2 : rxjava : 2.1.3'compile'io.reactivex.rxjava2 : rxandroid : 2.0.1'compile 'com.squareup.retrofit2 : 어댑터-rxjava2 : 2.3.0'compile 'de.greenrobot : eventbus : 3.0.0-beta1'compile'com.facebook.fresco : fresco : 0.11.0 '
<용도로 android : name = "android.permission.internet" />
MVP 모드를 사용하기 전에 하청 계약
순 패키지
API
public class api {public static string host = "http://120.27.23.105/product/";}Serviceapi
공개 인터페이스 serviceapi {@get ( "getProductDetail") flowable <xqbean> getxq (@Query ( "pid") int pid, @Query ( "소스") 문자열 str); @get ( "addcart") flowable <dadcart> 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);}성공적인 인터페이스
공개 인터페이스 onnetLisenter <t> {void success (t t);}개조 포장
공개 클래스 retrofithepler {public static okhttpclient okhttpclient; 공공 정적 서브 시아피 스와비애피; / *** 우선 순위 실행*/ static {getokhttpclient (); } public static alkhttpclient getokhttpclient () {if (okhttpclient == null) {synchronized (okhttpclient.class) {if (alkhttpclient == null) {okhttpclient = new okhttpclient (); }} return okhttpclient; } public static serviceapi getServiceapi () {if (serviceapi == null) {synchronized (alkhttpclient.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 ()) .create (okhttpclient). .addcalladapterFactory (rxjava2calladapterfactory.create ()) //. return return.create (tclass); }} 콩 패키지
자세한 내용은 콩 수업 페이지입니다
Public Class XQBEAN {/** * msg : * 판매자 : { "설명": "나는 가맹점 2", "아이콘": "http://120.27.23.105/images/icon.png", "이름": "Merchant 2", "ProductNums": 999, "5,"SellerId ":"2} " { "BargainPrice": 111.99, "CreateTime": "2017-10-14T21 : 48 : 08", "DetailUrl": "https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm=appshare&utm_campaign=TT_CAMPAGIN UNMAGONE 335139774 & utm_term = qqfriends ","이미지 ":"https://m.360buyimg.com/n0/jfs/t9004/210/1160 833155/647627/AD6BE059/59B4F4E1N9A2B1532.jpg! Q70.jpg | https : //360buyimg.com/n0/jfs/t7 504/338/63721388/491286/f5957F53/598E95F1N7F2ADB87.jpg! q70.jpg | https : //360buyimg.co M/N0/JFS/T7441/10/64242474/419246/ADB30A7D/598E95FBND989BA0A.JPG! Q70.JPG ","itemType ": 2 , "PID": 9, "Price": 78.99, "PSCID": 1, "Salenum": "Salenum": "Sellerid": 2, "Subhead": "모든 중반 축제"는 간단 할 수 없습니다. 당신이 어디에 있든, 당신은 항상 당신의 삶을 더 완전하게 만들기 위해 케이크가 필요합니다. 손가락 ","제목 ":"베이징 Daoxiangcun Daoxiangcun Mid-Autumn Festival Mooncake Old Beijing Mooncake Gift Box "} */ private String MSG; 개인 판매자 비안 판매자; 개인 문자열 코드; 개인 데이터 데이터; 공개 문자열 getmsg () {return msg; } public void setmsg (문자열 msg) {this.msg = msg; } public sellerBean getSeller () {return seller; } public void setseller (SellerBean Seller) {this.seller = 판매자; } public String getCode () {return code; } public void setCode (문자열 코드) {this.code = code; } public databean getData () {return data; } public void setData (Databean Data) {this.data = data; } public static class sellerbean {/** * 설명 : 나는 가맹점 2 * 아이콘 : http://120.27.23.105/images/icon.png * 이름 : Merchant 2 * ProductNums : 999 * 점수 : 5.0 * sellerid : 2 */private String 설명; 개인 문자열 아이콘; 개인 문자열 이름; 개인 INT ProductNums; 개인 이중 점수; 개인 int sellerid; 공개 문자열 getDescription () {return description; } public void setDescription (문자열 설명) {this.Description = 설명; } public String getIcon () {리턴 아이콘; } public void seticon (문자열 아이콘) {this.icon = 아이콘; } public String getName () {return name; } public void setName (문자열 이름) {this.name = 이름; } public int getProductNums () {return productNums; } public void setProductNums (int productNums) {this.productnums = productNums; } public double getScore () {반환 점수; } public void setScore (이중 점수) {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=qqqufriends * 이미지 : https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4 f4e1n9a2b1532.jpg! q70.jpg | https : //360buyimg.com/n0/jfs/t7504/338/63721 388/491286/f5957f53/598e95f1n7f2adb87.jpg! q70.jpg | https : //360buyimg.co M/N0/JFS/T7441/10/64242474/419246/ADB30A7D/598E95FBND989BA0A.JPG! Q70.JPG * ItemType : 2 * PID : 9 * 가격 : 78.99 * PSCID : 1 * 판매 : 2356 * SellerId : 2 * 부드럽 : 모든 중반 축제는 간단 할 수 없습니다. 당신이 어디에 있든, 당신은 항상 당신의 삶을 더욱 완전하게하기 위해 케이크 조각이 필요합니다. JD Mooncakes는 더 완벽한 JD 자체 운영, 번개 배달, 더 놀라움, 손가락으로 클릭하십시오 * 제목 : Beijing Daoxiangcun Daoxiangcun Mid-Autumn Festival Mooncake Old Beijing Mooncake Gift Box 655G */ 개인 이중 바겐 세일 프라이스; 개인 문자열 CreateTime; 개인 문자열 세부 사항; 개인 문자열 이미지; 개인 int itemtype; 개인 int pid; 개인 이중 가격; 개인 int pscid; 개인 INT Salesenum; 개인 int sellerid; 개인 문자열 소제목; 개인 문자열 제목; 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 (문자열 이미지) {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 () {반환 가격; } public void setPrice (이중 가격) {this.price = 가격; } public int getPscid () {return pscid; } public void setpscid (int pscid) {this.pscid = pscid; } public int getSalenum () {return salesenum; } public void setsalenum (int salesenum) {this.salenum = salesenum; } 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 (문자열 제목) {this.title = title; }}}콩이 카트에 추가되었습니다
공개 클래스 AddCart {private String msg; 개인 문자열 코드; 공개 문자열 getmsg () {return msg; } public void setmsg (문자열 msg) {this.msg = msg; } public String getCode () {return code; } public void setCode (문자열 코드) {this.code = code; }}제품 카테고리
Public Class Cartbean { /*** MSG : 요청 성공* 코드 : 0* 데이터 : [{ "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 ","이미지 ":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/ 56f0a08fnbd3a1235.jpg! q70.jpg | https : //360buyimg.com/n0/jfs/t2137/336/2 802996626/155915/E5E90D7A/56F0A09CN333E01BD0.jpg! Q70.jpg | https : //360buy img.com/n0/jfs/t1882/31/2772215910/389956/C8DBF370/56F0A0A2NA0C86.JPG ! q70.jpg | https : //360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531a a913/57709035N33857877.jpg! q70.jpg ","num ":"pid ": 24,"price ": 288,"pscid ": 2,"selected ": 0,"Sellerid ": 1,"Subhead ":"3 개의 Squirrels Snack ":"99, 100, 100, It of the that and the the that and the the the the that and the work and the work and the the work and the the work and the work work work work work work work " 》 ","제목 ":"3 개의 스 쿼리 너트 구운 간식 크림 피칸 225g/가방 "}, {"bargainprice ": 11800,"CreateTime ":"2017-10-10T17 : 33 : 37 ","DetailUrl ":"https://item.m.jd.com/proct/4338107 .html? utm#_source = androidapp & utm#_medium = appshare & utm#_campaign = t#_335139774 & utm#_term = qqfriends ","이미지 ":"https://m.360buyimg.com/n0/jfs/t6700 /155/209898076/156185/6CF95035/595DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD5NC3A7DAB5.JPG! Q70.JPG","NUM":2, " PID ":"57, "가격": 5199, "PSCID": 40, "Selected": 0, "SellerId": 1, "Subhead": "【i5 MX150 2G 비디오 메모리] Full HD 좁은 베젤 8g 메모리 256 SSD는 지문 인식 사전 설치된 Win10 시스템 ","제목 ":"Xiaomi (MI) 에어 13.3 인치 전체 금속 얇은 노트북 (i5-7200U 8G 256G SSD MX150 2G 독립 그래프 인식 Win10)을 지원합니다. Silver/R/N "}, {"BargainPrice ": 99,"CreateTime ":"2017-10-14T21 : 38 : 26 ","DetailUrl ":"https://item.m.jd.com/product/4345173.html? share & 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 : //360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644E3/594A3A12 n5b900606.jpg! q70.jpg ","num ":"1, "pid": 45, "price": "pscid": 39, "selected": 0, "sellerid": "Subhead": "HD 듀얼 카메라", 6GB Quall + Qualldragon 83 Monster! ""Title ":"OnePlus Mobile 5 (A5000) 6GB+64GB YueyanHui Full Network Connection Dual-Sec 듀얼 대기 모바일 중국 Unicom Telecom 4G 휴대폰 "}],"판매자 이름 ":"판매자 ": 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 ","이미지 ":"https://m.360buyimg.com/n0/jfs/t8284/363/1326459580/71585/6d3e8013/ 59B857F2N6CA75622.jpg! Q70.jpg | https : //360buyimg.com/n0/jfs/t9346/182/1406837243/28210 6/68af5b54/59b8480ane8af7f7f5c.jpg! q70.jpg | https : //m.360buyimg.com/n0/jfs/t8434/54/1359766 007/56140/579509D9/59B85801NFEA207DB.JPG! Q70.JPG ","Num ": 1,"PID ": 46,"Price ":"PSCID ": 39,"Selected ": 0,"SellerId ":"Subhead ":"새로운 iPhone " 다른 ","제목 ":"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_SOURC. 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예 "PSCID": "SELECTED": 0, "SELERID": 5, "SUBHEAD": "모든 중반 축제는 간단 할 수 없습니다. 당신이 어디에 있든, 당신은 항상 당신의 인생을 더 완전하게하기 위해 케이크가 필요합니다. Mooncake Old Beijing Mooncake Gift Box 655G "}],"SellerName ":"Merchant 5 ","SellerId ":"5 "}, {"List ": [{"bar GainPrice ": 11800,"CreateTime ":"2017-10-03T23 : 53 : 28 ","DetailUrl ":"https://mitem.jd.hk/ware/view.act ION? wareid = 198853309 & Cachekey = 1ACB07A701ECE8D2434A6AE7FA6870A1 ","images ":"https://m.360buyimg.com/ N0/JFS/T6130/97/1370670410/180682/1109582A/593276B1ND81FE723.JPG! Q70.JPG | https : //m.360buyimg.com/n 0/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/j FS/T5878/60/2557817477/30873/4502B606/593276CAN5A7D6357.JPG! Q70.JPG ","NUM ":"PID ": 62,"가격 ": 15999,"PSCID ": 40,"SELEREFTERED ":"SELERID ":" 1 위안을위한 컴퓨터 사무용 제품 및 5 위안의 기차 티켓으로 돌아 가기 (일단 반품이 끝나면) ","제목 ":"새로운 Apple 모델의 글로벌 구매 MacBook Pro Apple Laptop vp2 새로운 13 인치 바 i5/8g/256g "}] :"판매자 이름 ":"판매자 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 " , "이미지": "https://m.360buyimg.com/n0/jfs/t5887/201/859509257/69994/6bde9bf6/59224c24n e854e14c.jpg! q70.jpg | https : //360buyimg.com/n0/jfs/t5641/233/853609022/57374/5c73d281 /59224c24n3324d5f4.jpg! q70.jpg|https://m.360buyimg.com/n0/jfs/t5641/233/853609022/5737 4/5C73D281/59224C24N33324D5f4.jpg! Q70.jpg ","num ": 1,"pid ": 86,"price ": 777,"pscid ": 85,"선택된 ": 0,"SellerId ": 7,"Sublead ":"총 65%, ",", "", "", "": ":": ":": ":": ":": ":": ":": ":"Sublead ":"Sublead ":"Sublead ":"Sublead ":"Sublead ":": " 편안하고 간단한 세척 똑바로 바지 5 봉지 타이트한 청바지 941825 다크 그레이 33/32 (175/84a) "}],"판매자 이름 ":"가맹점 7 ","SellerId ":"7 "}, {"list ": [{"bargainprice ": 111.99,"CreateTime ":"2017-10-14T21 : 39 : 05 ","DetailUrl ":"https://item.m.jd.com/prod uct/4719303.html? utm_source = androidapp & utm_medium = appshare & utm_campaign = t_335139774 & utm_term = qqfriends ","이미지 ":"https : //m.36 0buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59B4F4E1N9A2B153 2.jpg! q70.jpg | https : //m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f 5957f53/598e95f1n7f2adb87.jpg! q70.jpg | https : //m.360buyimg.com/n0/jfs/t74 41/10/64242474/419246/adb30a7d/598e95fbnd989ba0a.jpg! q70.jpg ","num ": 12,"p ID ":"Price ":"PSCID ": 1,"Selected ": 0,"SellerId ": 17,"Subhead ":"모든 중반 축제는 어디에 있든, 당신의 삶이 더 완전한 JD 자체 수술, 가벼운 전달을 위해서는 케이크가 필요합니다. " Daoxiangcun Mid-Autumn Festival Mooncake Old Beijing Mooncake Gift Box 655g "}],"SellerName ":"Merchant 17 ","Merchant 17 ","SellerId ":"17 "}, {"List ": [{"BargainPrice ": 111.99,"CreateTime ":"2017-14T21 : 39 : 05 ",": ":": ":": ":": "heturl": "heturl": "2017-14T21 : 05" : //item.m.jd.com/product/4719303.html? utm_source = androidapp & utm_medium = appshare & utm_campaign = t_335139774 & utm_term = qqfriends ","https : // m .360BUYIMG.com/N0/JFS/T9004/210/1160833155/647627/AD6BE059/59B4F4E1N9A2B 1532.jpg! q70.jpg | https : //m.360buyimg.com/n0/jfs/t7504/338/63721388/491286 /f5957f53/598e95f1n7f2adb87.jpg! q70.jpg|https://m.360buyimg.com/n0/jfs/t 7441/10/64242474/419246/adb30a7d/598e95fbnd989ba0a.jpg! q70.jpg ","num ": 4, "PID": "Price": "Price": "PSCID": 1, "Selected": 0, "SellerId": 18, "Subhead": "모든 중반 축제"는 간단 할 수 없습니다. 당신이 어디에 있든, 당신은 항상 당신의 인생을 더 완전하게 만들기 위해서는 당신의 삶을 더 완전하게 만들기 위해서는 항상 케이크가 필요합니다. daoxiang 마을 Daoxiang 마을 중반 축제 문케이크 오래된 베이징 문 케이크 선물 상자 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/1 370670410/180682/1109582a/593276B1nd81fe723.jpg! q70.jpg | https : //360buy img.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7nbd94ef1f.jp g! q70.jpg | https : //360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c93 88feb/593276b7nbd94ef1f.jpg! q70.jpg | https : //360buyimg.com/n0/jfs/t5815/ 178/2614671118/51656/7f52d137/593276c7n107b725a.jpg! q70.jpg | https : //m.36 0buyimg.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 개의 유안 쿠폰을 구입하고 (한 번 돌아 오는 것), "제목", "", "", "", "", "" VP2 새로운 13 인치 바 i5/8g/256g "}],"SellerName ":"판매자 20 ","SellerId ":"20 "}, {"List ": [{"bargainprice ": 111.99,"CreateTime ":"2017-10-14T21 : 39 : 05 ","detailUrl ":"https://item.m.jd.com/4719303.html?utm_source=Android p & utm_medium = appshare & utm_campaign = t_335139774 & utm_term = qqfriends ","이미지 ":"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,"pric e ":"PSCID ": 1,"Selected ": 0,"SellerId ": 21,"Subhead ":"모든 중반 축제는 어디에 있든, 당신의 삶이 더 완전한 JD 자체 운영, 가벼운 전달을 위해서는 항상 케이크가 필요합니다. " Daoxiangcun Mid-Autumn Festival Mooncake Old Beijing Mooncake Gift Box 655g "}],"SellerName ":"Merchant 21 ","SellerId ":"21 "}] */ private String MSG; 개인 문자열 코드; 개인 목록 <Databean> 데이터; 공개 문자열 getmsg () {return msg; } public void setmsg (문자열 msg) {this.msg = msg; } public String getCode () {return code; } public void setCode (문자열 코드) {this.code = code; } public list <databean> getData () {return data; } public void setData (list <databean> data) {this.data = data; } public static class databean { /*** 목록 : [{ "BargainPrice": 22.9, "CreateTime": "2017-10-14T21 : 48 : 08", "DetailUrl": "https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_med IUM = AppShare & utm_campaign = t_335139774 & utm_term = qqfriends ","images ":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08 fnbd3a1235.jpg! q70.jpg | https : //360buyimg.com/n0/jfs/t2137/336/2802996 626/155915/e5e90d7a/56f0a09cn33e01bd0.jpg! q70.jpg | https : //360buyimg.c OM/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,"squirrels snack snack, 50, 100, 100, 100, 100, 그리고 50, 100, and and and and and and 100, 50, 50, 그리고 50, 그리고 50, 50 구매》 ","제목 ":"3 개의 스 쿼린 너트 로스트 스낵 크림 피칸 225g/가방 "}, {"bargainprice ": 11800,"CreateTime ":"2017-10-10T17 : 33 : 37 ","https://item.m.jd.com/proct/4338107.h. tml? utm#_source = androidapp & utm#_medium = appshare & utm#_campaign = t#_335139774 & utm#_term = qqfriends ","이미지 ":"https://m.360buyimg.com/n0/jfs/t6700/ 155/2098998076/156185/6CF95035/595DDDDDDDDDDDDDDDDDDDDDD5NC3A7DAB5.JPG! Q70.JPG ","NUM ":"2, "PID": 57, "가격": 5199, "PSCID": 40, "SELECTER": "SOLLERID": "Subghead": ":": ":": ":": ": MX150 2G 비디오 메모리] Full HD 좁은 베젤 8g 메모리 256 SSD는 지문 인식 사전 설치된 Win10 시스템 ","제목 ":"Xiaomi (MI) 에어 13.3 인치 전체 금속 얇은 노트북 (i5-7200U 8G 256G SSD MX150 2G 독립 그래프 인식 Win10)을 지원합니다. Silver/R/N "}, {"BargainPrice ": 99,"CreateTime ":"2017-10-14T21 : 38 : 26 ","DetailUrl ":"https://item.m.jd.com/product/4345173.html? share & 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 : //360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644E3/594A3A12 n5b900606.jpg! q70.jpg ","num ":"1, "pid": 45, "price": "pscid": 39, "selected": 0, "sellerid": "Subhead": "HD 듀얼 카메라", 6GB Quall + Qualldragon 83 Monster! ""Title ":"OnePlus Mobile 5 (A5000) 6GB+64GB YueAnhui Full Network Connect Dual Sim Sim Sim SIM DUAL Mobile Mobile Mobile Mobile Mobile "}] * SellerName : Merchant 1 * SellerID : 1 */ Private String SellerName; 개인 문자열 판매자; 비공개 목록 <SlistBean> 목록; 개인 부울 수표; 공개 부울 ischeck () {반환 점검; } public void setCheck (부울 점검) {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 <STREBEAN> getList () {반환 목록; } 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/ https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fnbd3a1235.jpg! q70.jpg | https : //360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cn33e01bd0.jpg! q70.jpg | https : //360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2na0c86.jpg! q70.jpg | https : //360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531AA913/57709035N33857877.jpg! q70.jpg * NUM : 1 * PID : 24 * 가격 : 288.0 * PSCID : 2 * 선택 : 0 * SellerId : 1 * Subheads Special Offer : 50 개 구매 영역에서 구매 50 개, 지역에서 199 개를 구매 한 경우 100 개 할인, 서둘러 구매 및 3 개의 Squirrel Nuts Screamy Pygium/ PIGIANPRICE; 개인 문자열 CreateTime; 개인 문자열 세부 사항; 개인 문자열 이미지; 개인 int Num; 개인 int pid; 개인 이중 가격; 개인 int pscid; 개인 INT가 선택된; 개인 int sellerid; 개인 문자열 소제목; 개인 문자열 제목; 개인 int cou = 1; public int getcou () {return co; } public void setcou (int cou) {this.cou = cou; } 개인 부울 수표; 공개 부울 ischeck () {반환 점검; } public void setCheck (부울 점검) {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 (문자열 이미지) {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 () {반환 가격; } public void setPrice (이중 가격) {this.price = 가격; } public int getPscid () {return pscid; } public void setpscid (int pscid) {this.pscid = pscid; } public int getSelected () {return 선택; } 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 (문자열 제목) {this.title = title; }}}} 앱
공개 클래스 MyApp는 응용 프로그램을 확장합니다 {@override public void oncreate () {super.oncreate (); fresco.initialize (this); }} 레이어를 봅니다
먼저 두 개의 인터페이스를 작성하십시오
public interface icart {void showlist (list <cartbean.databean> grouplist, list <list <cartbean.databean.listbean >> childrist);} 공개 인터페이스 iview <t> {void showbean (t t); void showstr (문자열 s);}메인 페이지 레이아웃
<? 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-souto" XMLNS : 도구 = "http://schemas.android.com/tools"Android : layout_width = "match_parent"android : layout_height = "mays_parent"android : "수직"도구 : Context = "com.bwie.zhangzhen20110108.mainactivity"<expandablelistview Android : id = "@+id /elv"Android : layout_weight = "1"1 "Android : layout_width ="wrap_content "Android : layout_height ="wrap_content " /> <linearlayout android : layout_weight ="9 "Android ="horizontal "android : layout_width =" "" "" "" ". 방향 _" Android : layout_height = "match_parent"> <Checkbox Android : id = "@+id /quanxuan"android : layout_width = "wrap_content : layout_height ="wrap_content " /<TextView Android :"and alloid : 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 : id = "@+Zongjia" 안드로이드 : layout_width = "wrap_content"Android : layout_height = "wrap_content"Android : 텍스트 = "총 가격 : 0.0" /> <textView Android : "Total 0 항목"Android : id = "@+id /id /id /id /id /id /id /id /id /id /id _"wrap_content "Android : </linearLayout> <TextView Android : Text = "Total Checkout"Android : back
메인 페이지
공개 클래스 Mainactivity는 AppCompatactivity emplements icart {private expandablelistview melv; 개인 확인란 Mquanxuan; 개인 TextView Mzongjia; Private TextView mtvcount; Private MyExpandableAdapter MyExpandableAdapter; @override protected void onecreate (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 >> childrist) {myexpandableadapter = new myexpandableadapter (grouplist, this, childrist); Melv.setAdapter (MyExpandableAdapter); for (int i = 0; i <grouplist.size (); i ++) {melv.expandgroup (i); }} // 전송 된 값 수신 @subscribe public void onpriceandCount (countandprice cp) {mzongjia.settext ( "Total"+cp.getCount ()+"item"); mtvcount.settext ( "Total :"+cp.getPrice ()); } // 전송 된 값을받습니다 @Subscribe public void onpriceAndCount1 (messgeevent event) {// 선택한 상태 mquanxuan.setchecked (event.ischeck ()); } @override protected void ondestroy () {super.ondestroy (); eventBus.getDefault (). Ungegister (this); }}두 번째 페이지 레이아웃
<? xml version = "1.0"alcoding = "utf-8"?> <linearlayout xmlns : android = "http://schemas.android.com/apk/res/android"xmlns : 툴 = "http://schemas.android.com/tools : layout_width ="andlayout_width = ""http:/schemas.android.com/tools " Android : layout_height = "match_parent"Android : Orientation = "수직"Android : id = "@+id/activity_add"도구 : context = "com.bwie.zhangzhen20170108.addactivity"> <com.facebook.drawee.view.simpledRaweeview : layout_width = "300DDPP :" Android : id = "@+id /xqsdv1"Android : layout_gravity = "Center"Android : layout_height = "300dp" /> <TextView Android : id = "@+id /tvtitle1"Android : layout_width = "match_parent"androng : : layout_height = "wrap_content" />>>>>>>>>>>>>>>>>>> <layout_height = "wrap_content" 안드로이드 : "수평"안드로이드 : layout_width = "match_parent"android : layout_height = "wrap_content"> <버튼 안드로이드 : id = "@+id/tiaozhuan1"android : layout_weight = "1"Android : "텍스트 ="android_width = "Android_parent" Android : layout_height = "wrap_content"/<버튼 안드로이드 : id = "@+id/tianjia1"Android : layout_weight = "1"Android : "act to cart"android : layout_width = "match_parent"Android : layout_height = "wrap_content"</linearlayout> </linearlayout> </linearlayout>
쇼핑 카트 코드 구현
공개 클래스 AddActivity는 AppComPatactivity를 확장합니다. 개인 TextView mtvtitle; 개인 버튼 mtiaozhuan; 개인 버튼 Mtianjia; 개인 linearlayout maddactivity; 개인 XQPRESENTER XQPRESENTER; @override protected void onecreate (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 = (버튼) findViewById (r.id.tiaozhuan1); mtiaozhuan.setonclicklistener (this); mtianjia = (버튼) findViewById (r.id.tianjia1); mtianjia.setonclicklistener (this); madDactivity = (linearLayout) findViewById (r.id.Activity_ADD); } @override public void onclick (view v) {switch (v.getId ()) {기본값 : break; // MainActivity (쇼핑 카트) CASE R.ID.TIAOZHUAN1 : STARTACTIVITY (새로운 의도 (this, mainActivity.class)); 부서지다; CASE R.ID.TIANJIA1 : XQPRESENTER.GETADD (); 부서지다; } } @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);//Address converted to URI mXqsdv.setImageURI(uri); mTvtitle.setText(data.getTitle()+"/n"+data.getPrice()); } @Override public void showStr(String s) { Toast.makeText(this, s, Toast.LENGTH_SHORT).show(); }} eventbus包
设置一个数量和价格的类
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
public class MessgeEvent { private boolean check; public boolean isCheck() { return check; } public void setCheck(boolean check) { this.check = check; }} 모델
实现详情页model层的接口
public interface IXQModel { public void getXQ(int pid, String str, final OnNetLisenter<XQBean> cgsb);}实现详情页model
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
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层
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层
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); } }); }}어댑터
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()); //Click the status of the first-level checkbox holder.group_cb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dataBean.setCheck(holder.group_cb.isChecked()); //Change the status of all children changeChildState(groupPosition,holder.group_cb.isChecked()); EventBus.getDefault().post(jS()); //Judge the status of all selected by judging the checkbox of the first level 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.price.setText("¥:"+price+""); String title = listBean.getTitle(); 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 click event holder.child_cb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { listBean.setCheck(holder.child_cb.isChecked()); EventBus.getDefault().post(jS()); //If the checkBox of the second level is selected, let the checkBox of the first level checkBox check if(holder.child_cb.isChecked()) { if (ischeckAllchild(groupPosition)) { //Change the status of the first level checkBox changeGroupstatus(groupPosition,true); //Change the status of the selected state by judging the status of the first level CheckBox to changeMianQXstatus(checkGroupAll()); } }else{ changeGroupstatus(groupPosition,false); changeMianQXstatus(checkGroupAll()); } notifyDataSetChanged(); } }); //Click add function 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()); } } }); //Click the function of decreasing holder.jian.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int cou = listBean.getCou(); if(cou==1) { Toast.makeText(context, "The minimum number is 1", Toast.LENGTH_SHORT).show(); return;} holder.tv_num.setText(--cou+""); listBean.setCou(cou); if (holder.child_cb.isChecked()) { EventBus.getDefault().post(jS()); } } }); //Click to delete 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; } /** * Determine that all the second level is CheckBox or not checked* */ 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; }} true를 반환합니다. } /** * Calculate quantity and price* Get the second-level CheckBox by traversing the first-level. If it is the selected selected state, count their total quantity and price*/ 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(jiaage); return countAndPrice; } /** * Change the status of the first-level list*/ private void changeGroupstatus(int groupPosition,boolean flag ){ CartBean.DataBean dataBean = groupdata.get(groupPosition); dataBean.setCheck(flag); } /** * Change the status of all selected* */ private void changeMianQXstatus(boolean flag){ MessgeEvent messageEvent = new MessgeEvent(); messageEvent.setCheck(flag); EventBus.getDefault().post(messgeEvent); } /** * Determine whether all the first level are selected*/ private boolean checkGroupAll(){ for (int i = 0; i < groupdata.size(); i++) { if(!groupdata.get(i).isCheck()){ return false; }} true를 반환합니다. } /** * Change the status of all children*/ 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); } } /** * Change all selected*/ 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
<?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
<?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>
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.