购物车

本文介绍如何使用ExpandableListView实现购物车功能,包括布局设计、数据填充及与JSON数据交互的过程。通过示例代码展示了购物车商品分组及子项的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.先写布局

<ExpandableListView
        android:id="@+id/elv"
        android:layout_above="@+id/lin_end"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></ExpandableListView>

    <LinearLayout
        android:id="@+id/lin_end"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:gravity="center_vertical"
        >
        <CheckBox
            android:id="@+id/all"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/all_count"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="合计:0"
            android:gravity="center"

            />
        <TextView
            android:id="@+id/all_money"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="计算:0"
            android:gravity="center"

            />
    </LinearLayout>


2.导library

3.创建jsonbean类

4. 购物车

for (int i=0;i<data.size();i++){
                flist.add(new GroupBean(data.get(i).getTitle(),false));
                List<ChildBean> slist=new ArrayList<>();
                for (int j=0;j<flist.size();j++){
                    slist.add(new ChildBean(data.get(j).getTitle(),data.get(j).getPrice()+"",data.get(j).getImages(),false,1));
                }
                clist.add(slist);
            }
            CartUtils.setCartData(MainActivity.this,flist,clist,elv,all,all_count,all_money);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值