Android实现简单购物车功能

  

本文实例为大家分享了Android实现购物车功能的具体代码,供大家参考,具体内容如下

  

MainActivity布局:

  

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android "   android: layout_width=" match_parent "   android: layout_height=" match_parent "   面向android:=按怪薄北?      LinearLayout & lt;   android: id=癅 + id/top_bar”   android: layout_width=" match_parent "   android: layout_height=" 48 dp "   android:背景=" # E24146”   面向android:=按怪薄北?   & lt; TextView   android: id=癅 + id/标题”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:重力="中心"   android: minHeight=" 48 dp "   android:文本="购物车”   android:输入textColor=" # ffffff "   android: textSize=" 17 sp "/比;   & lt;/LinearLayout>      & lt;列表视图   android: id=癅 + id/视图”   android: layout_width=" match_parent "   android: layout_height=" 0 dp”   android: layout_weight=" 1 "   android: childIndicator=" @null "   android: groupIndicator=癅null”比;   & lt;/ListView>      LinearLayout & lt;   android: layout_width=" match_parent "   android: layout_height=" 50 dp”   面向android:="水平"比;      LinearLayout & lt;   android: layout_width=" 0 dp”   android: layout_height=" match_parent "   android: layout_weight=" 2.5 "   android:重力=" center_vertical "   面向android:="水平"比;      & lt;复选框   android: id=癅 + id/all_chekbox”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_gravity=" center_vertical "   android: layout_marginLeft=" 10 dp”   android: layout_marginRight=" 4 dp "   android:按钮=" @drawable/check_box_bg”   android:选中标记=" & # 63;android: attr/listChoiceIndicatorMultiple”   android:重力="中心"   android: minHeight=" 64 dp”   android: paddingLeft=" 10 dp”   android: textAppearance=" & # 63; android: attr/textAppearanceLarge”   android:可见性=翱杉?祝辞      & lt; TextView   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_marginLeft=" 5 dp "   android:文本="合计:“   android: textSize=" 16 sp "   android: textStyle=按蟮ā?比;      & lt; TextView   android: id=癅 + id/tv_total_price”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android:文本=¥0.00   android:输入textColor=" @color/紫色   android: textSize=" 16 sp "   android: textStyle=按蟮ā?比;   & lt;/LinearLayout>      & lt; TextView   android: id=癅 + id/tv_delete”   android: layout_width=" 0 dp”   android: layout_height=" match_parent "   android: layout_weight=" 1 "   android:背景=" @color/橙”   android:点击=" true "   android:重力="中心"   android:文本="删除”   android:输入textColor=" # FAFAFA "/比;      & lt; TextView   android: id=癅 + id/tv_go_to_pay”   android: layout_width=" 0 dp”   android: layout_height=" match_parent "   android: layout_weight=" 1 "   android:背景=" # E24146”   android:点击=" true "   android:重力="中心"   android:文本="付款(0)”   android:输入textColor=" # FAFAFA "/比;   & lt;/LinearLayout>      & lt;/LinearLayout>      之前      

        进口android.os.Bundle;   进口android.support.v7.app.AppCompatActivity;   进口android.view.View;   进口android.widget.CheckBox;   进口android.widget.ListView;   进口android.widget.TextView;   进口android.widget.Toast;      进口java.util.ArrayList;   进口java.util.HashMap;   进口java.util.Iterator;   进口并不知道;   进口java.util.Map;   进口java.util.Random;      公共类MainActivity AppCompatActivity实现CartAdapter延伸。RefreshPriceInterface View.OnClickListener {      私人列表视图列表视图;   私人复选框cb_check_all;   私人TextView tv_total_price;   私人TextView tv_delete;   私人TextView tv_go_to_pay;      私人CartAdapter适配器;      私人双totalPrice=0.00;   私人int totalCount=0;   私人List

Android实现简单购物车功能