Android实现购物车功能

本文介绍了如何在Android中实现购物车功能,包括在main.xml布局文件中设置全选和反选复选框,item.xml中定义每个商品条目的显示,创建Goods类存储商品信息,MainActivity中初始化并处理复选框事件,以及自定义MyAdapter适配器来更新购物车状态和总价。
摘要由CSDN通过智能技术生成


main

<?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">

    <CheckBox
        android:id="@+id/btn_all"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="全选" />

    <CheckBox
        android:id="@+id/btn_revers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="反选" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="400dp"></ListView>

    <TextView
        android:id="@+id/all_money"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="总价"
        android:textStyle="bold"
        android:textSize="30dp"/>
</LinearLayout>


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:orientat

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值