Giter VIP home page Giter VIP logo

Comments (6)

OCNYang avatar OCNYang commented on May 16, 2024

感谢你发现这个致命 bug 和提出合理的建议,我将马上修复它。

from cartlayout.

OCNYang avatar OCNYang commented on May 16, 2024

这是具体我的做法:

if ((ICartItem.TYPE_GROUP == mDatas.get(position - 1).getItemType()) &&
(((position + 1) == mDatas.size()) ||
(ICartItem.TYPE_GROUP == mDatas.get(position + 1).getItemType()))) {
isLastOne = true;
}

并为此我已经更新了新的版本 v1.0.1

from cartlayout.

Kong-xyZ avatar Kong-xyZ commented on May 16, 2024

谢谢,你的写法比我的好,学习了。

from cartlayout.

Kong-xyZ avatar Kong-xyZ commented on May 16, 2024

@OCNYang 你好,请问如果我要获取被选中的商品,重新组合成一个二维数组(第一层是商铺信息,第二层是对应的商品信息)时应该怎么处理?

from cartlayout.

OCNYang avatar OCNYang commented on May 16, 2024

    /**
     * 以组格式化选中的 Item
     * #mAdapter 列表的适配器
     *
     * @return
     */
    public List<IGroupItem> getCheckItemByFormat() {
        List<IGroupItem> lists = new ArrayList<>();
        int groupPosition = -1;
        for (int i = 0; i < mAdapter.getData().size() && mAdapter.getData().get(i).getItemType() == ICartItem.TYPE_GROUP; i++) {

            if (groupPosition != -1) {
                IGroupItem groupItemBean;

                List<IChildItem> childItemBeans = new ArrayList<>();
                
                for (int j = i; groupPosition < j && mAdapter.getData().get(j).isChecked(); j--) {//循环获取选中的商品
                    childItemBeans.add(((IChildItem) mAdapter.getData().get(j)));
                }
                if (childItemBeans.size() != 0) {
                    groupItemBean = new GroupItemBean();
                    groupItemBean.setItemId(mAdapter.getData().get(groupPosition).getItemId());
                    groupItemBean.setItemType(mAdapter.getData().get(groupPosition).getItemType());

                    groupItemBean.setChilds(childItemBeans);
                    lists.add(groupItemBean);
                }
            }

            groupPosition = i;
        }

        //添加最后一个店铺
        IGroupItem groupItemBean;
        List<IChildItem> childItemBeans = new ArrayList<>();
        for (int j = mAdapter.getData().size(); groupPosition < j && mAdapter.getData().get(j).isChecked(); j--) {//循环获取选中的商品
            childItemBeans.add(((IChildItem) mAdapter.getData().get(j)));
        }
        if (childItemBeans.size() != 0) {
            groupItemBean = new GroupItemBean();
            groupItemBean.setItemId(mAdapter.getData().get(groupPosition).getItemId());
            groupItemBean.setItemType(mAdapter.getData().get(groupPosition).getItemType());

            groupItemBean.setChilds(childItemBeans);
            lists.add(groupItemBean);
        }

        return lists;
    }

这是写的大概的逻辑代码,未验证对错。

另一种方式:
在初始化数据时,是可以把店铺的商品数据设置到 GroupItemBean.setChilds(List childs),这样的话你就不用像上面那么麻烦了。

from cartlayout.

Kong-xyZ avatar Kong-xyZ commented on May 16, 2024

好的,我试下,谢谢

from cartlayout.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.