Dieser Artikel teilt den spezifischen Code von Rxjava Retrofit -Implementierungseinkaufswagen für die Referenz aller. Der spezifische Inhalt ist wie folgt
Reproduktionsbild:
1. Abhängigkeit
Annotationsprozessor 'com.SquareUp.Retrofit2: Converter-Gson: 2.3.0' Compile 'com.facebook.Fresco: Fresco: 0.12.0' Compile 'com.facebook kompilieren Sie 'com.facebook 'com.SquareUp.okhttp3: Okhttp: 3.9.0' kompilieren 'com.google.code.gson: gson: 2.8.1'
2. Layout
1..
<?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: Gewichtsum = "1"> <textView Android: id = "@+id/txt_delete" Android: layout_width = "30dp" Android: layout_Height = "30dp" Android: text = "Ableitung" Android: Gravity = "Center" Android: Hintergrund: Hintergrund:#8B948B "/<Boyda", "#"#"#"#8B948B "/<Boids", "#"#"#"#"#8B948b"/> Android: id = "@+id/et_number" Android: layout_Margintop = "2DP" Android: layout_width = "50dp" Android: layout_Height = "30dp" Android: Hintergrund = "@Drawable/Edit" Android: Layout_Weight = "0,00" und "0,00". android:id="@+id/txt_add" android:layout_width="30dp" android:layout_height="30dp" android:text="plus" android:gravity="center" android:background="#8b948b"/> </LinearLayout>
2. Produktdetails Layout Aktivität_Main
<? Android: layout_width = "match_parent" Android: layout_Height = "match_parent"> <linearlayout Android: layout_width = "match_parent" Android: layout_Height = "Match_Parent" Android: Orientierung = "Vertical"> <com.dacebook.draawe.vee.view.view.view.Sim.siwaWe. Android: id = "@+id/my_image_view" Android: layout_width = "match_parent" Android: layout_Height = "450dp" Fresco: PlaceholderImage = "@mipMap/ic_launcher"/> <textView android: id = "@+idtit"@+id/garge/garge/garge_tit: Android: layout_Height = "Wrap_Content" Android: layout_Margin = "10dp" Android: text = "aahhh es ist deins" Android: textsize = "20dp" /> <textView Android: id = "@+id /gary_price" android: layout_width = "Wrack_" Wrack_width = "Wrack_" Wrack_ "Wrack_" wrack_width = "wrack_content" android "android" android: Android: layout_Margin = "10dp" Android: text = "¥ 18132" Android: textColor = "#DC5F2E" Android: textsize = "18dp" /> <textView Android: layout_width = "Wrack_content" Android: Layout_HELTS = "WRACKELT" 10 DRACTEL = "10DPLE". Android: text = "Ich bin ein Händler19" Android: textSize = "16dp" /> < /linearlayout> <linearlayout Android: layout_alignparentbottom = "true" Android: layout_width = "match_parent" android: layout_hight = "50dp" und orientation = "horizontal"> <) Android: id = "@+id/btn_addcart" Android: layout_weight = "1" Android: layout_width = "0dp" Android: layout_Height = "Match_Parent" Android: Hintergrund = "#ffc207" Android: Text = "addt to cading to carts to cart"/> <button: Id = "@@"@"@"@"| Android: layout_weight = "1" Android: layout_width = "0dp" Android: layout_Height = "Match_Parent" Android: Hintergrund = "#ff6b06" Android: text = "jetzt kaufen"/> </linearlayout> </relatelayout>
3. Einkaufswagen Layout Aktivität_Main2
<?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"> <!--Head Layout-> <linearlayout Android: id = "@+id/top_bar" android: layout_width = "match_parent" android: layout_height = "48dp" Android: Hintergrund = "#f7f7f7" android: orientation = "matchical"> <relatelayout: Layout: Layout: Layout: Layout: Layout: Layout: Layout: Layout: Layout: Layout: Layout_width = "matparent"> < Android: layout_Height = "48dp" Android: Hintergrund = "@Android: Farbe/transparent" Android: Orientierung = "Vertikal"> <ImageView Android: id = "@+id/back" Android: layout_width = "48dp" Android: Layout_HEISTS = "48DP" Android: Layout_high = "48DP" und "48DP" und "48DP" und "48DP" und "48DP" und "48DP" und "48DP" und "48DP" und "48DP" und "48DP". 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="Shopping Cart" Android: textColor = "#1a1a1a" Android: textSize = "16sp" /> <textView Android: id = "@+id /bearbeiten" Android: layout_width = "Wrap_Content" Android: Layout_Height = "Wrack_Content" Android: Layout_Alntright = "echte" echte "echt" und Layout_Alntreue = "echte" echte "echt" und Layout_Alntreue = "echte" echte "echte" und "echte" und "echt" und "foodout_Alntreue". Android: Gravity = "Center" Android: minHeight = "48dp" Android: text = "bearbeiten" Android: textColor = "#1A1A1a" Android: textSize = "14sp" Android: Sichtbarkeit = "sichtbar"/> </relatelayout> </linearLayout> </linearlayout> <EXTIFABLABLABLISHEL. Android: layout_width = "match_parent" Android: layout_Height = "0dp" Android: layout_weight = "1" Android: ChildInDicator = "@null" Android: GroupIndicator = "@null"> </explodablelistView> <linearlayout android: layout_width = "Match_Parz" 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="select all"/> <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" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 "1" 1 " Android: layout_width = "match_parent" Android: layout_Height = "Wrap_Content" Android: Orientierung = "Horizontal" Android: Gravity = "Right"> <textView Android: layout_width = "wrack_content" android: layout_high = "frap- Android: text = "Total:" Android: textSize = "18sp" Android: textStyle = "BOLD" /> <textView Android: id = "@+id /total_price" android: layout_width = "Wrack_Content" Android: Layout_Height = "Wrack_content" android: text: text: ¥ 0.00 "¥ 0.00" ¥ 0.00 "¥ 0.00" ¥ 0.00 " Android: textColor = "#f23232" Android: textSize = "16sp" Android: textStyle = "BOLD"/> </linearlayout> <textView Android: id = "@+id/Total_Number" Android: Layout_Width = "match_Parent_Parent: pieces" 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: Hintergrund = "#fd7a05" Android: Clickable = "True" Android: Gravity = "Center" Android: text = "Clear" Android: textColor = "#fafafa" /> <textView Android: id = "@+id /tv.go_to_del" android: layout: layout_width = "pike_parent" " Android: layout_Height = "match_parent" Android: layout_weight = "3" Android: Hintergrund = "#e2231c" Android: klickable = "true" android: gravity = "center" android: text = "delete" android: textcolor = "#fafafa" android: " </Linearlayout>
4. Sekundärlisten-Layout für Gruppenebene ex_group_item
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#cfc3c3" android:orientation="horizontal"> <CheckBox android:id="@+id/group_checkbox" android:layout_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. Sekundärliste Unter-Layout ex_child_item
<? 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 = "Wrack_Content" Android: Layout_AligentleLft = "true_content" android: layout. 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_launchner" Android: Layout_Below = "@+id/shopname" android: louid: louid: louid: louid: louid: louid: louid: louid: louid: louid: louid: Layout_AlignParentleft "@+true_name" android: louid: louid: louid: louid: Layout_AlignParentleft. Android: layout_alignParentStart = "true" />-> <com.facebook Fresco: PlaceholderImage = "@mipmap/ic_launcher" Android: layout_below = "@+id/shop_name" Android: layout_alignParentleft = "true" Android: layout_alignParentstart = "true"/> <textView android: id = "@+ide/shops/shopSe_price": "@+id/shops_precrice": "@+id/shops_precrice". 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" ¥ 20 "¥ 20" ¥ 20 "¥ 20" ¥ 20 " Android: textColor = "#f23232"/> <com.bwei Android: layout_Margintop = "30dp" Android: layout_Marginleft = "140dp" App: links_text = "-" App: right_text = "+" app: Middle_text = "1" Android: Focusable = "False"> </com.bwei.Gepeng.MyView.AddDeview.addEletn.addEletdel. 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 = "delete"/> </relATelayout> </linearlayout>
3.. Entitätsklasse
1. MessageBean
Paket com.bwei.gepeng.entity; öffentliche Klasse MessageBean <T> {privater String -Code; private T -Daten; private String -MSG; privater Verkäufer von Sellerbean; public String getCode () {return code; } public void setCode (String -Code) {this.code = code; } public t getData () {returndaten; } public void setData (t data) {this.data = data; } public String getmsg () {return msg; } public void setmsg (String msg) {this.msg = msg; } public SellerBean geteller () {Rückgabeverkäufer; } public void setseller (sellerbean seller) {this.seller = seller; } public statische Klasse SellerBean {/** * Beschreibung: Ich bin ein Händler 19 * Symbol: http://120.27.23.105/images/icon.png * Name: Händler 19 * Produktnums: 999 * Punktzahl: 5.0 * SellerID: 19 */private String Beschreibung; privates String -Symbol; privater Zeichenfolge Name; private int productNums; private doppelte Punktzahl; private int sellerid; public String getDescription () {Rückgabe Beschreibung; } public void setDescription (String Beschreibung) {this.description = Beschreibung; } public String geticon () {return icon; } public void seticon (String -Symbol) {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 getCore () {return Score; } public void setScore (doppelte Punktzahl) {this.score = Score; } public int getellerId () {return sellerid; } public void setsellerId (int sellerId) {this.sellerId = sellerId; }}}2. GOODSSHOWBEAN
Paket com.bwei.gepeng.entity; öffentliche Klasse Warenshowbean {Private Double Bargainprice; private String createtime; private String detailurl; private Stringbilder; private int ittype; private int pid; privater Doppelpreis; privat int pscid; privates Int Salesenum; private int sellerid; private String -Unterhead; privater String -Titel; public double getbargainprice () {return bargainprice; } public void setbargainprice (doppelte Bargainprice) {this.BargainPrice = bargainprice; } public String getCreateTime () {return createTime; } public void setCreateTime (String createTime) {this.createTime = CreateTime; } public String getDetailurl () {retailUrl; } public void setDetailurl (String detailUrl) {this.detailurl = detailUrl; } public String getImages () {return Images; } public void setImages (String -Bilder) {this.images = Bilder; } 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 () {Rückgabepreis; } public void setPrice (Doppelpreis) {this.price = price; } public int getpscid () {return pScid; } public void setpscid (int pScid) {this.pScid = pScid; } public int GetAsalenum () {return salesenum; } public void setSalenum (int salesenum) {this.salenum = salesenum; } public int getellerId () {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 "Warenshowbean {" + "bargainprice =" + bargainprice + ", createTime = '" + createTime +'/'' + ", detailUrl = '" + detailUrl +'/'' + ", Images = ' +' + ' +', PIDTE + ',' '', '' + ',", ",", ",", ",", "," "," "," "," "," "," "," "," "," "," "," "," "." price = " + price +", pscid = " + pscid +", salesenum = " + salesenum +", sellerId = " + sellerId +", subhead = '" + subhead +'/'' +", title = '" + title +'/''} '; }}3. Cartbean
Paket com.bwei.gepeng.entity; importieren java.util.list; public class cartbean {private String Sellername; private String sellerid; private Liste <ListBean> Liste; public String getellername () {return Sellername; } public void setsellername (String Sellername) {this.sellername = Sellername; } public String getellerId () {return sellerId; } public void setsellerId (String sellerID) {this.sellerId = sellerId; } publiclist <ListBean> getList () {return list; } public void setList (list <listBean> list) {this.list = list; } öffentliche statische Klassenlistenbean {private Double BargainPrice; private String createtime; private String detailurl; private Stringbilder; private int num; private int pid; privater Doppelpreis; privat int pscid; private int ausgewählt; private int sellerid; private String -Unterhead; privater String -Titel; public double getbargainprice () {return bargainprice; } public void setbargainprice (doppelte Bargainprice) {this.BargainPrice = bargainprice; } public String getCreateTime () {return createTime; } public void setCreateTime (String createTime) {this.createTime = CreateTime; } public String getDetailurl () {retailUrl; } public void setDetailurl (String detailUrl) {this.detailurl = detailUrl; } public String getImages () {return Images; } public void setImages (String -Bilder) {this.images = Bilder; } 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 () {Rückgabepreis; } public void setPrice (Doppelpreis) {this.price = price; } public int getpscid () {return pScid; } public void setpscid (int pScid) {this.pScid = pScid; } public int getSelected () {return ausgewählt; } public void setSelected (int ausgewählt) {this.selected = ausgewählt; } public int getSelerid () {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
Paket com.bwei.gepeng.entity; public class GroupBean {private String Sellername; private boolesche Gruppierung; Public GroupBean (String Sellername, Boolean Groupucb) {this.sellername = Sellername; this.gropucb = Groupucb; } public String getellername () {return Sellername; } public void setsellername (String Sellername) {this.sellername = Sellername; } public boolean isgropucb () {return Groupucb; } public void setgropucb (boolean Groupucb) {this.gropucb = Groupucb; } @Override public String toString () {return "GroupBean {" + "Sellername = '" + Sellername +'/'' + ", Groupucb =" + Groupucb + '}'; }}5.Childbean
Paket com.bwei.gepeng.entity; BILDBUCH PUSTOR CLASSE {privater String -Titel; private Stringbilder; privater Doppelpreis; private int num; privat boolesche Kinder; privat boolean btn; private int pid; öffentliche Kinder (String -Titel, Stringbilder, Doppelpreis, int num, boolean childCB, boolean Btn, int pid) {this.title = title; this.images = Bilder; this.price = Preis; 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 -Bilder) {this.images = Bilder; } public double getPrice () {Rückgabepreis; } public void setPrice (Doppelpreis) {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. Schnittstelle
1.APIService
Paket com.bwei.gepeng.http; import com.bwei.gepeng.entity.cartbean; import com.bwei.gepeng.entity.goodsshowbean; import com.bwei.gepeng.entity.messageBean; importieren java.util.list; import Java.util.map; importieren io.reactivex.flowable; import retrieve2.http.get; import retrieve2.http.QueryMap; öffentliche Schnittstelle Apiservice {// Produktdetails abfragen 75 //http://120.27.23.105/product/getProductDetail?pid=75&Source=Android @get ("Produkt/GetProductDetaLe") Flowable <MessageBean <GoodeshowBean >> GetNews (@QueryMap MAP). // Query -Einkaufswagen // http: //120.27.23.105/product/getCarts? Uid = 3802 & source = android @get ("product/getCarts") Flowable <MessageBean <list <cartbean >>> getCart (@QueryMap Map <String, String> map); // Einkaufswagen löschen // http: //120.27.23.105/product/getCarts? Uid = 3802 & source = android @get ("product/deleteCart") Flowable <messageBean <list <cartbean >>> getdel (@QueryMap Map <string, string> map); // Einkaufswagen hinzufügen // http: //120.27.23.105/product/addcart? Uid = 3802 & pid = 75 & source = android @get ("product/addcart") fließbar <MessageBean <List <Cartbean >>> @QueryMap Map <String> Map <String> Map); } 2.iview [java] klare copypublic interface iview {void OnSuccess (Objekt O, String -Tag); void onfailed (Ausnahme E, String -Tag); } 3.iPresenter [Java] Sehen Sie sich einfach Copyimport java.util.map an; public interface ipresenter {void getData (MAP <String, String> Map, String -Tag); } 4.Imodel [java] Sehen Sie sich einfach Musstimport Java.util.Map an; public interface iModel {void getData (Map <String, String> Map, String -Tag); }5. Code
1. Benutzerdefinierte Ansicht AddDeletEview
Paket com.bwei.gepeng.myview; importieren android.content.context; import Android.content.res.typedarray; import android.graphics.color; import Android.util.attributeset; android.view.view importieren; importieren android.widget.edittext; importieren Android.widget.LinearLayout; android.widget.textView importieren; import com.bwei.gepeng.r; Public Class AddDELETEView erweitert linearLayout {private OnadddelclickListener -Listener; private EditText etNumber; // Geben Sie eine Klick -Callback -Schnittstelle für die externe Verwendung der öffentlichen Schnittstelle auf. void ondelclick (View v); } public void setonadddelclickListener (OnadddelClickListener -Listener) {if (louser! = null) {this.Listener = listener; }} public addDELETEVIEW (Kontextkontext) {this (context, null); } public addDeletEview (Kontextkontext, Attributeet attrs) {this (Context, Attrs, 0); } public addDeletEview (Kontextkontext, Attributeet Attrs, int DefStyleattr) {Super (Kontext, Attrs, DefStyleattr); InitView (Kontext, Attrs, Defstyleattr); } private void initView (Kontextkontext, Attributeet Attrs, int DefStyleattr) {view.inflate (Kontext, R.Layout.Layout_Add_Delete, this); // das Steuerelement textView txtDelete = findViewById (R.id.txt_delete) abrufen; TextView txtadd = findViewById (r.id.txt_add); etnumber = findViewById (r.id.et_number); TypeDarray typeDarray = context.obtainstyledattributes (attrs, r.Stylable.AddDELETEViewStyle); String LeftText = typeDarray.getString (r.Stylable.AddDELETEVIEWSTYLE_LEFT_TEXT); String rightText = typeDarray.getString (r.Stylable.AddDELETEViewStyle_Right_Text); String middletExt = typeDarray.getString (r.Stylable.AddDELETEViewStyle_Middle_text); int color = typeDarray.getColor (r.Stylable.AdddeletEviewStyle_Left_text_color, color.red); txtDelete.setText (linksText); txtadd.setText (rightText); etnumber.setText (MidDletExt); txtDelete.setTextColor (Farbe); // recycle typedarray.recycle (); txtDelete.setonClickListener (new OnclickListener () {@Override public void onclick (Ansicht anzeigen) {listener.ondelclick (Ansicht);}}); txtadd.setonClickListener (neuer OnclickListener () {@Override public void Onclick (Ansicht anzeigen) {listener.onaddclick (Ansicht);}}); } // Geben Sie eine externe Methode zur Änderung von Zahlen public void setNumber (int number) {if (number> 0) {etnumber.setText (number+""); }} // Geben Sie eine externe Methode an, um die aktuelle Nummer public int getNumber () {string string = etnumber.getText () zu erhalten. ToString (); int i = Integer.ParseInt (String); kehre I zurück; }} 2. Nachrüstanschlüsse Nachrüstungen nachrüsteten
Paket com.bwei.gepeng.http; importieren java.io.ioException; import akhttp3.httpurl; import OKHTTP3.Interceptor; import akhttp3.okhttpclient; import akhttp3.request; import akhttp3.response; Import retrieve2.retrofit; import retrieve2.adapter.rxjava2.rxjava2calladapterFactory; Import Retrieve2.Converter.gson.gsonConverterFactory; öffentliche Klasse Nachrüstungen {private statische flüchtige Nachrüstungstanz; Private Final Nachrüstung nachrüst; private retrofitutils () {Okhttpclient client = new Okhttpclient.builder (). AddInterceptor (neuer 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 getAtAteService () {apiservice apiservice = renfit.create (apiservice.class); apiservice zurückgeben; } class Logger implementiert Interceptor {@Override public response intercept (Chain Chain) löscht IoException {anforderungsoriental = caint.Request (); Httpurl url = original.url (). Newbuilder () .addQueryparameter ("Quelle", "Android") .build (); // Anforderung an Request Request Request = Original.NewBuilder () .url (URL) .build (); return chain.Proceed (Anfrage); }}} 3.m Schicht
Paket 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; importieren java.util.list; import Java.util.map; importieren io.reactivex.flowable; öffentliches Klassenmodell implementiert Imodel {privater Zeitungssgerender Moderator; public model (Zeitungssender -Moderator) {this.Presenter = Moderator; } @Override public void getData (Map <String, String> Map, String -Tag) {if (tag.equals ("cart") {Flowable <messageBean <list <cartbean >>> Flowable = retrofitutils.getInstance (). Moderator.get2 (fließbar, Tag); } else if (tag.equals ("good")) {flowable <messageBean <GoodsShowbean >> Flowable = Retrofitutils.getInstance (). Presenter.get (fließbar, Tag); } else if (tag.equals ("del")) {Flowable <messageBean <list <cartbean >>> Flowable = renfitutils.getInstance (). Moderator.get3 (fließbar, Tag); } else if (tag.equals ("add")) {Flowable <messageBean <list <cartbean >>> Flowable = renfitutils.getInstance (). Moderator.get4 (fließbar, Tag); }}} 4.P -Schicht
Paket 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; importieren java.util.list; import Java.util.map; importieren io.reactivex.flowable; importieren io.reactivex.android.schedulers.androidschedulers; Import IO.Reactivex.Schedulers.Schedulers; Import IO.Reactivex.SubScrippen.Disposablesubscriber; Public Class NewsPresenter implementiert iPresenter {private iview iview; private idiablesubscriber <MessageBean <GoodsShowbean >> Abonnent; private idiablesubscriber <messageBean <list <cartbean >>> subscriber2; private Dispositsubscriber <MessageBean <Liste <cartbean >>> Abonnent3; private idiablesubscriber <messageBean <list <cartbean >>> subscriber4; public void attachView (iview iview) {this.iview = iview; } @Override public void getData (MAP <String, String> Map, String -Tag) {Modell model = neues Modell (this); model.getData (Karte, Tag); } public void detachView () {if (iview! = null) {iview = null; } if (subscriber! }} if (subscriber2! }} if (subscriber3! }} if (subscriber4! }}} // Abfrageinkaufswagen public void Get (fließbar <messageBean <GoodsShowbean> Flowable, Final String Tag) {subscriber = fließbar public void onnext (MessageBean <GAROSSHOWBEAN> LISTMESSAGEBEAN) {if (ListMessageBean! @Override public void onComplete () {}}); } // Produktdetails abfragen 75 public void get2 (fließbar <messageBean <list <cartbean >>> fließbar, endgültiger String -Tag) {subscriber2 = fließbar @Override public void Onnext (MessageBean <list <cartbean >>> list) {if (list! = Null) {list <cartbean> data = list.getData (); } @Override public void onComplete () {}}); } // Einkaufswagen public void get3 löschen (fließbar <messageBean <list <cartbean >>> fließbar, endgültiger String -Tag) {subscriber3 = fließbar public void Onnext (MessageBean <list <cartbean >> list) {if (list! } // Einkaufswagen public void Get4 hinzufügen (fließbar <messageBean <list <cartbean >>> fließbares, endgültiges String -Tag) {subscriber4 = fließbar void onnext (MessageBean <list <cartbean >>> list) {if (list! = null) {String code }} 5. MainActivity -Produktdetails Seite Seite
Paket com.bwei.gepeng.view; import android.content.intent; importieren Android.os.bundle; importieren android.support.v7.app.appcompataktivität; android.view.view importieren; android.widget.textView importieren; importieren android.widget.toast; import com.bwei.gepeng.r; import com.bwei.gepeng.entity.goodsshowbean; import com.bwei.gepeng.presenter.newSpresenter; com.facebook.dawee.view.Impledraaweeview; import Java.util.hashMap; import Java.util.map; Butterknife.BindView importieren; Butterknife.butterknife importieren; Butterknife import.onclick; MainActivity der öffentlichen Klasse erweitert die AppCompataktivität implementiert IView {@bindView (R.Id.My_Image_View) SimpledRaweeView MyImageView; @BindView (r.id.goods_title) textView Goodstitle; @BindView (r.id.goods_price) textView goodsprice; privates Zeitungssender -Moderator; @Override Protected void OnCreate (Bündel SavedInstancestate) {Super.oncreate (SavedInstancestate); setContentView (r.layout.Activity_main); Butterknife.bind (this); Moderator = neuer Zeitraumspresenter (); Moderator.attachView (this); //http://120.27.23.105/product/getProductDetail?pid=75&Source=Android Map <String, String> map = new HashMap <> (); map.put ("pid", "75"); Moderator.getData (Karte, "Waren"); } @Override public void OnSuccess (Objekt O, String -Tag) {if (tag.equals ("Waren") {if (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 (Ausnahme E, String -Tag) {} @Onclick ({R.id.Btn_addcart, R.id.BTN_SHOPPING}) public void onViewClicked (Ansicht anzeigen) {Switch.getId ()) {case r.b.Btn_Adn_Adn_Addcart: MAPTCART: MAPS: MACK <SING, MAGN = MABEL = MABEL = MABEL = MABEL) (MABEL); map.put ("uid", "3802"); map.put ("pid", "75"); Presenter.getData (Karte, "add"); //Toast.makeText(MainActivity.this,"add erfolgreich ", toast.length_short) .show (); brechen; Fall R.Id.BTN_SHOPPING: Intent Intent = New Intent (MainActivity.This, Main2Activity.Class); Startaktivität (Absicht); brechen; }}} 6. Sekundärlistenadapter expanAlaBleadapter
Paket com.bwei.gepeng.adapter; importieren android.content.context; android.view.view importieren; android.view.viewGroup importieren; importieren android.widget.baseexpandablelistAdapter; importieren Android.widget.button; importieren Sie Android.widget.CheckBox; android.widget.textView importieren; importieren 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.adddeletteview; import com.bwei.gepeng.view.main2Activity; com.facebook.dawee.view.Impledraaweeview; Import Java.util.ArrayList; importieren 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; } //Interface callback 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; } //Level 1 group @Override public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) { //Load view 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()); //Group check button 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 groupCb = i.isGropuCb(); if(!groupCb){ 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 button"+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 button"+gchecked+""+size, Toast.LENGTH_SHORT).show(); childBeen.get(i).get(r).setChildCb(false); } } notifyDataSetChanged(); main.changesum(childBeen); } }); return view; } //Second-level group @Override public View getChildView(final int i, final int i1, boolean b, View v, ViewGroup viewGroup) { //Load view 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; //Control the visible and hidden if(childBeen.get(i).get(i1).isBtn()){ shop_delete.setVisibility(View.VISIBLE); }else{ shop_delete.setVisability(View.INVISIBLE); } //Delete button listening shop_delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { onDleGoods.onDelGoods(i,i1,childBeen.get(i).get(i1).getPid()+""); } }); //AddDelClickListener(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,"The minimum number of users is 1",Toast.LENGTH_SHORT).show(); } number--; adv.setNumber(number); childBeen.get(i).get(i1).setNum(number); main.changesum(childBeen); } }); //Checkbox of secondary group listen 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 button"+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
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; importieren 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 flagdel = 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); //Get the secondary list adapter 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(); brechen; case R.id.edit: if(flagedit){ tvGoToPay.setVisability(View.GONE); tvGoToDel.setVisability(View.VISIBLE); }else{ tvGoToPay.setVisability(View.VISIBLE); tvGoToDel.setVisability(View.GONE); } for (List<ChildBean> i1 : childBeen) { for (int r = 0; r < i1.size(); r++) { i1.get(r).setBtn(flagedit); } } flagedit = !flagedit; expandableAdapter.notifyDataSetChanged(); brechen; case R.id.all_chekbox: boolean checked = allCheckbox.isChecked(); //Change the first-level item check box for (GroupBean i : groupBeen) { i.setGropuCb(checked); } //Change the second-level item check box for (List<ChildBean> i1 : childBeen) { for (int r = 0; r < i1.size(); r++) { i1.get(r).setChildCb(checked); } } expandableAdapter.notifyDataSetChanged(); changesum(childBeen); brechen; 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); } brechen; } } if(flagdel){ break; } } } //Toast.makeText(Main2Activity.this,flagdel+"",Toast.LENGTH_SHORT).show(); brechen; } } //Recursively delete 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; brechen; } } if(flag){ break; } } } //Total price of calculation and quantity public void changesum(List<List<ChildBean>> childBeen) { int count = 0; doppelte Summe = 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("Total products:" + count + "piece"); } }6.附
shape图edit
<?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
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); } }Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.