购物车的二级列表适配器

Android购物车的功能实现(二级列表) 阅读详情
package com.lbp.yuekao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.TextView;

import com.lbp.yuekao.R;
import com.lbp.yuekao.bean.GoosBean;
import com.lbp.yuekao.bean.MessageEvent;
import com.lbp.yuekao.bean.PriceAndCountEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Created by Administrator on 2018/1/17 0017.
 */

public class MyExAdapter extends BaseExpandableListAdapter {
    private Context context;
    private List<GoosBean.DataBean> groupList;
    private List<List<GoosBean.DataBean.DatasBean>> childList;
    private final LayoutInflater inflater;

    public MyExAdapter(Context context, List<GoosBean.DataBean> groupList, List<List<GoosBean.DataBean.DatasBean>> childList) {
        this.context = context;
        this.groupList = groupList;
        this.childList = childList;
        inflater = LayoutInflater.from(context);
    }
    @Override
    public int getGroupCount() {
        return groupList.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return childList.get(i).size();
    }

    @Override
    public Object getGroup(int i) {
        return groupList.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return childList.get(i).get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) {
        View view1;
        final GroupViewHolder groupViewHolder;
        if(view==null){
            groupViewHolder = new GroupViewHolder();
            view1 = inflater.inflate(R.layout.item_parent_market, null);
            groupViewHolder.cbGroup = view1.findViewById(R.id.cb_parent);
            groupViewHolder.tv_number = view1.findViewById(R.id.tv_number);
            view1.setTag(groupViewHolder);
        }
        else{
            view1 = view;
            groupViewHolder = (GroupViewHolder) view1.getTag();
        }
        final GoosBean.DataBean dataBean = groupList.get(i);
        groupViewHolder.cbGroup.setChecked(dataBean.isChecked());
        groupViewHolder.tv_number.setText(dataBean.getTitle());
        groupViewHolder.cbGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dataBean.setChecked(groupViewHolder.cbGroup.isChecked());
                changeChildCbState(i,groupViewHolder.cbGroup.isChecked());
                EventBus.getDefault().post(compute());
                changeAllCbState(isAllGroupCbSelected());
                notifyDataSetChanged();
            }
        });
        return view1;
    }



    @Override
    public View getChildView(final int i, final int i1, boolean b, View view, ViewGroup viewGroup) {
        View view1;
        final ChildViewHolder holder ;
        if(view==null){
            holder = new ChildViewHolder();
            view1 = inflater.inflate(R.layout.item_child_market, null);
            holder.cbChild = view1.findViewById(R.id.cb_child);
            holder.tv_tel = view1.findViewById(R.id.tv_tel);
            holder.tv_content = view1.findViewById(R.id.tv_content);
            holder.tv_time = view1.findViewById(R.id.tv_time);
            holder.tv_price = view1.findViewById(R.id.tv_pri);
            holder.tv_del = view1.findViewById(R.id.tv_del);
            holder.iv_add = view1.findViewById(R.id.iv_add);
            holder.iv_del = view1.findViewById(R.id.iv_del);
            holder.tv_num = view1.findViewById(R.id.tv_num);
            view1.setTag(holder);
        }else{
            view1=view;
            holder = (ChildViewHolder) view1.getTag();
        }
        final GoosBean.DataBean.DatasBean datasBean = childList.get(i).get(i1);
        holder.cbChild.setChecked(datasBean.isChecked());
        holder.tv_tel.setText(datasBean.getType_name());
        holder.tv_content.setText(datasBean.getMsg());
        holder.tv_time.setText(datasBean.getAdd_time());
        holder.tv_price.setText(datasBean.getPrice() + "");
        holder.tv_num.setText(datasBean.getNum() + "");

        holder.cbChild.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                datasBean.setChecked(holder.cbChild.isChecked());
                PriceAndCountEvent priceAndCountEvent = compute();
                EventBus.getDefault().post(priceAndCountEvent);
                if (holder.cbChild.isChecked()){
                    if(isAllChildCbSelected(i)){
                        changGroupCbState(i,true);
                        changeAllCbState(isAllGroupCbSelected());
                    }
                }else{
                    changGroupCbState(i,false);
                    changeAllCbState(isAllGroupCbSelected());
                }
                notifyDataSetChanged();
            }
        });

        holder.iv_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = datasBean.getNum();
                holder.tv_num.setText(++num + "");
                datasBean.setNum(num);
                if (holder.cbChild.isChecked()) {
                    PriceAndCountEvent priceAndCountEvent = compute();
                    EventBus.getDefault().post(priceAndCountEvent);
                }
            }
        });
        holder.iv_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = datasBean.getNum();
                if (num == 1) {
                    return;
                }
                holder.tv_num.setText(--num + "");
                datasBean.setNum(num);
                if (holder.cbChild.isChecked()) {
                    PriceAndCountEvent priceAndCountEvent = compute();
                    EventBus.getDefault().post(priceAndCountEvent);
                }
            }
        });
        holder.tv_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<GoosBean.DataBean.DatasBean> datasBeen = childList.get(i);
                GoosBean.DataBean.DatasBean remove = datasBeen.remove(i1);
                if (datasBeen.size() == 0) {
                    childList.remove(i);
                    groupList.remove(i);
                }
                EventBus.getDefault().post(compute());
                notifyDataSetChanged();
            }
        });
        return view1;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }



    private void changeChildCbState(int groupposition ,boolean flag){
        List<GoosBean.DataBean.DatasBean> beans = childList.get(groupposition);
        for (int i = 0; i <beans.size() ; i++) {
            GoosBean.DataBean.DatasBean bean = beans.get(i);
            bean.setChecked(flag);
        }
    }

    private void changeAllCbState(boolean flag) {
        MessageEvent event = new MessageEvent();
        event.setChecked(flag);
        EventBus.getDefault().post(event);
    }

    private void changGroupCbState(int groupPosition, boolean flag) {
        GoosBean.DataBean dataBean = groupList.get(groupPosition);
        dataBean.setChecked(flag);
    }

    private boolean isAllGroupCbSelected() {
        for (int i = 0; i < groupList.size(); i++) {
            GoosBean.DataBean dataBean = groupList.get(i);
            if (!dataBean.isChecked()) {
                return false;
            }
        }
        return true;
    }

    class GroupViewHolder {
        CheckBox cbGroup;
        TextView tv_number;
    }

    class ChildViewHolder {
        CheckBox cbChild;
        TextView tv_tel;
        TextView tv_content;
        TextView tv_time;
        TextView tv_price;
        TextView tv_del;
        ImageView iv_del;
        ImageView iv_add;
        TextView tv_num;
    }

    private PriceAndCountEvent compute() {
        int count = 0;
        int price = 0;
        for (int i = 0; i < childList.size(); i++) {
            List<GoosBean.DataBean.DatasBean> datasBeen = childList.get(i);
            for (int j = 0; j < datasBeen.size(); j++) {
                GoosBean.DataBean.DatasBean datasBean = datasBeen.get(j);
                if (datasBean.isChecked()) {
                    price += datasBean.getNum() * datasBean.getPrice();
                    count += datasBean.getNum();
                }
            }
        }
        PriceAndCountEvent priceAndCountEvent = new PriceAndCountEvent();
        priceAndCountEvent.setCount(count);
        priceAndCountEvent.setPrice(price);
        return priceAndCountEvent;
    }

    private boolean isAllChildCbSelected(int groupPosition) {
        List<GoosBean.DataBean.DatasBean> datasBeen = childList.get(groupPosition);
        for (int i = 0; i < datasBeen.size(); i++) {
            GoosBean.DataBean.DatasBean datasBean = datasBeen.get(i);
            if (!datasBean.isChecked()) {
                return false;
            }
        }
        return true;
    }

    public void changeAllListCbState(boolean flag) {
        for (int i = 0; i < groupList.size(); i++) {
            changGroupCbState(i, flag);
            changeChildCbState(i, flag);
        }
        EventBus.getDefault().post(compute());
        notifyDataSetChanged();
    }
}



帮助类 
package com.lbp.yuekao.bean;

/**
 * Created by peng on 2017/11/17.
 */

public class MessageEvent {
    private boolean checked;

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }
}

package com.lbp.yuekao.bean;

/**
 * Created by peng on 2017/11/17.
 */

public class PriceAndCountEvent {
    private int price;
    private int count;

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }
}


购物车二级列表+全选全不选+联动价格 二级适配器 public class CartsAdapter extends RecyclerView.Adapter<CartsAdapter.ViewHolder> { private Context context; private List<CartBean.DataBean.ListBean> cartsdata; public CartsAdapter(Con... 阅读详情

相关推荐

C#与YOLOv8工业缺陷检测实战:从算法到PLC集成的工程化落地

目标检测作为计算机视觉的核心任务,其原理是通过深度学习模型在图像中定位并识别物体。这项技术的关键价值在于将AI的感知能力转化为实际生产力,尤其在工业自动化领域,它能实现高效、精准的视觉检测。在工业缺陷检测这一典型应用场景中,稳定性和实时性是核心挑战。本文聚焦于如何将YOLOv8这一先进的目标检测模型,与C#上位机开发及工业相机硬件深度集成,构建一个能够7x24小时稳定运行的智能检测系统。文章深入探讨了从模型训练、ONNX部署,到与PLC通信联调的完整工程化路径,并针对工业环境中常见的稳定性、性能及调试问题提

weixin_33508411的博客 236

购物车

//MainActivity 页面package guobao.bwie.com.gwc;import android.app.Activity;import android.content.Context;import android.content.DialogInterface;import android.os.Bundle;import android.os.Handler;import

LSJ44的博客 1230

两张 300I Duo 部署 Qwen3.5‑32B

开发者成功使用两张华为300IDuo(共4颗Ascend310P3芯片)部署Qwen3/Qwen3.5的30B/32B模型,并公开详细步骤。关键点包括:硬件需两张300IDuo(每芯片44GB显存),软件需CANN≥24.1和MindIE2.3.0专用镜像。部署流程涵盖驱动安装、模型下载(需修改为FP16格式)、容器启动、张量并行配置(TP=4)等环节。实测显示每芯片显存占用20-35GB,系统稳定运行。该方案已在知乎等平台验证可行,适用于Qwen3.5-32B等同类模型。

evering的博客 2254

二级购物车的Adapter判断

import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.Check

这个不能实现 1万+

基于 Python 的 LIF 模型:探索神经元同步与小世界网络

首先,我们定义了一个LIFNeuronself.soma.L = self.soma.diam = 12.6157 # 固定神经元形状self.cm = cm # 电容self.V_rest = V_rest # 静息电位self.V = V_rest # 初始化膜电位在初始化过程中,每个神经元被赋予初始的静息电位,并且其膜电位会在后续的模拟过程中动态变化。

qq_36224726的博客 1423

RK3588部署Zipformer模型问题总结

本文分享了在RK3588嵌入式设备上部署小米Zipformer语音识别模型时遇到的问题及解决方法。主要遇到两个问题:1)在rknn_model_zoo例程编译时出现静态库版本不兼容,通过重新编译kaldi-native-fbank库并修改链接路径解决;2)sherpa-onnx编译时提示缺少portaudio库,通过修改编译脚本启用相关宏定义后成功编译。最终成功在RK3588上运行Zipformer模型,测试结果显示该模型具有较好的识别效果和实时性(RTF=0.22),验证了其在边缘设备上的适用性。

pkyang2004的博客 2145

二级列表购物车适配器啊

package com.example.aason.zhushayuekaomini.adapter; import android.content.Context; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.Layout...

Aasons的博客 167

基于STM32设计的万能红外遥控器(学习型)

当前介绍了一种基于STM32微控制器设计的红外遥控器,支持接收解码功能和发送功能,可以将接收的码原样发送出去。 红外遥控器作为智能设备控制方式之一,在一定程度上满足了人们对于快速方便控制的需求。 当前设计的红外遥控器支持学习模式和发送模式。通过矩阵键盘上的数字键选择发送对应的控制码。 一共支持学习10个控制码,对应矩阵键盘上的数字。0~9。

6559

android二级列表购物车

一.导入EventBus的依赖 compile 'org.greenrobot:eventbus:3.1.1' eventBus必须注册 EventBus.getDefault().register(this); 必销毁 //销毁方法 @Override protected void onDestroy() { super.onDestroy();

W1256754982的博客 1183

ISO21434 组织网络安全管理(二)

为了实现网络安全工程,该组织建立并维护网络安全治理和网络安全文化,包括网络安全意识管理、能力管理和持续改进。这涉及到指定针对本文档的目标进行独立审计的特定于组织的规则和过程。 为了支持网络安全工程,该组织实施了网络安全的管理系统,包括管理工具和应用质量管理系统。

qq_42357877的博客 1322

IP-Guard安全网关实例

企业相关情况: 1.OA系统,主要为日常工作使用,该系统IP为192.168.1.2,端口为8080; 2.文件共享服务器,用于存放日常工作资料和文档,该文件共享服务器的IP为192.168.1.1,其中\\192.168.1.1\private 目录中的存放着公司重要文档,不能随意外传; 3.安全网关已采用串联的方式联入网络,IP为192.168.2.6,所有机器访问OA系统和文件共享服务...

IP-Guard专栏 706

购物车二级列表全选、反选/适配器

public class Frag01 extends Fragment implements BaseView { private RecyclerView mRecycler; private TextView mTvPrice; private TextView mTvMoney; private ShopCarAdapter adapter; private BasePresenter p...

Jang_AnGe的博客 321

【专栏必读】王道考研408数据结构+算法设计与分析万字笔记使用说明及章节导航

各位老铁思维导图在我整理完笔记后会放上去的,我需要根据王道的思维导图重新再做一遍 文章目录一:有关注意事项二:关于专栏三:学习建议四:各专栏导航(各位老铁别催,质量优先)(1)第一章:绪论(2)第二章:线性表(3)第三章:栈和队列第四章:串第五章:二叉树第六章:图 首先感谢王道大大(手动比心),很用心在做了,大家可以看其中两节是否符合胃口 (王道408考研数据结构)第五章树-第三节1:二叉树遍历(先序、中序和后序) (王道408考研数据结构)第五章树-第四节2:平衡二叉树(AVL)及其旋转 一:有.

快乐江湖的博客 5万+

购物车二级列表适配器

package wld.bawei.com.myjindong.Adapter; import android.content.Context; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.uti

大神大咖大牛 403

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

仿京东购物车适配器(二级列表)

//布局页面 &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height...

chenyibai的博客 233

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

android 用二级列表实现仿京东购物车

2.首先先自定义一个二级列表package com.example.jingdong.erji; import android.content.Context; import android.util.AttributeSet; import android.widget.ExpandableListView; /** * Created by huoxuebin on 2018/4/24....

huoxuebin0316的博客 1004

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Android_二级列表购物车逻辑

二级列表适配器: package activity.example.com.jindongdemo.Adapter; import android.content.Context; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.Bas

Android___vv的博客 791

二级列表的购物车-适配器

package com.example.recycler.adapter; import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.C

My9973636800的博客 367

仿京东购物车Deom

写代码前要先加上权限和依赖: android:name="android.permission.READ_EXTERNAL_STORAGE" /> android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> android:name="android.permission.INTERNET" /> 依赖: compile

biggrand的博客 1397

RecyclerView实现二级列表

那今天就教大家使用RecyclerView来实现二级列表的购物车 废话不多说 直接上代码 权限 android:name="android.permission.INTERNET"> android:name="android.permission.READ_EXTERNAL_STORAGE" /> android:name="android.permission.WRIT

cm1606530815的博客 4768

android购物车分类,Android实现二级列表购物车功能

本文实例为大家分享了Android实现二级列表购物车功能的具体代码,供大家参考,具体内容如下MainActivity:package com.baway.twoshopcar;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android...

weixin_33210666的博客 514

安卓购物车二级列表简单展示(仿京东,淘宝效果)

首先导入依赖 implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.squareup.okhttp3:okhttp:3.1.2' implementation 'com.facebook.fresco:fresco:0.12.0' implementation 'com.squareup.re...

weixin_44285793的博客 779

仿京东、淘宝实现购物车(二级列表的形式)

本章仿京东、淘宝实现的形式是通过二级列表实现的,网络请求工具类是通过okHttp实现的 本章使用到的依赖 //相关依赖 //okhttp implementation 'com.squareup.okhttp3:okhttp:3.11.0' //Gson implementation 'com.google.code.gson:gson:2.8.1' ...

mingxiangzhimin的博客 1173

Android购物车的总结

购物车布局<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match

wrpbk的博客 582

购物车的具体实现步骤

//数据库创建 ```java package soexample.umeng.com.day_04_greendao.app; import android.app.Application; import soexample.umeng.com.day_04_greendao.dao.DaoMaster; import soexample.umeng.com.day_04_greendao...

qq_26014095的博客 305

android 购物车二级列表实现

首先看个效果图: 在我们做这个是时候,首先必须一定要导入权限: uses-permission android:name="android.permission.INTERNET" /> uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> uses-permission androi

wqzfy的博客 866
上一篇: 购物车的布局文件
下一篇: 购物车的工具类
忙着写BUG
博客等级 码龄9年 11粉丝 48原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值