Comments (6)
感谢你发现这个致命 bug 和提出合理的建议,我将马上修复它。
from cartlayout.
这是具体我的做法:
CartLayout/cartlayout/src/main/java/com/ocnyang/cartlayout/CartAdapter.java
Lines 141 to 145 in 91a4306
并为此我已经更新了新的版本 v1.0.1
from cartlayout.
谢谢,你的写法比我的好,学习了。
from cartlayout.
@OCNYang 你好,请问如果我要获取被选中的商品,重新组合成一个二维数组(第一层是商铺信息,第二层是对应的商品信息)时应该怎么处理?
from cartlayout.
/**
* 以组格式化选中的 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.
好的,我试下,谢谢
from cartlayout.
Related Issues (6)
- RecyclerView刷新问题 HOT 1
- 关于获取选中数据的问题 HOT 5
- 您好 这个group 可以支持单选吗? HOT 7
- 如果想点击组进行折叠 怎么搞 HOT 7
- 想获取被选中的商品id。。。好像没这个方案 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cartlayout.