现功能如下:ListView 嵌套ListVIew 中,第一个ListView 内容项为 卖家信息,包含卖家名称和CheckBox 其作用可以点击卖家进入卖家中心,点击CheckBox 则卖家的商品全部选中,在当前卖家页面中的ListVIew 其内容为 当前卖家的商品信息.包含商品信息和CheckBox 当前卖家下的所有商品都选中,则父选框都选中,有一个未选中则父选框不选中.
效果图:
代码先思路:在卖家数据集合中 定义 boole
1.卖家模型层
//卖家ID
private int fShopID;
//卖家名称
private String fShopName;
//整个卖家选中
private boolean isShopCheck;
2.给卖家适配器 复制 和 结算的全选
this.cartList=cartList;
cartAdapter = new CartAdapter(this,cartList,handler);
cartListView.setAdapter(cartAdapter);
结算全选
chk_Cart_allCheck=(CheckBox) findViewById(R.id.chk_Cart_allCheck);
chk_Cart_allCheck.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked)
{
// TODO 自动生成的方法存根
for (CartModel li : cartList)
{
if (isChecked) // 如果选中 则所有卖家为ture
{
li.getShop().setIsShopCheck(true);
} else
{ // 未选中则所有的为false
li.getShop().setIsShopCheck(false);
}
}
cartAdapter.notifyDataSetChanged();
}
});
3. 卖家适配器Adapter 中GetVIew
@Override
public View getView( int position, View convertView, ViewGroup parent)
{
// TODO 自动生成的方法存根
convertView = mInflater.inflate(R.layout.cart_list, null);
TextView tv_shopName=(TextView)convertView.findViewById(R.id.tv_cart_list_ShopName);
tv_shopName.setText(CartList.get(position).getShop().getfShopName());
CheckBox chk_Cart_list_AllCheckBox=(CheckBox) convertView.findViewById(R.id.chk_Cart_list_AllCheckBox);
chk_Cart_list_AllCheckBox.setTag(CartList.get(position).getShop().getfShopID());
final int fCurrentIndex=position;
if(CartList.get(position).getShop().getIsShopCheck())
{
chk_Cart_list_AllCheckBox.setChecked(true);
}
//根据购物车的卖家ID 显示卖家的商品信息
MyListView lv_Cart_List_Product=(MyListView)convertView.findViewById(R.id.lv_Cart_List_Product);
CheckBox chk_Cart_list_AllCheckBox=(CheckBox) convertView.findViewById(R.id.chk_Cart_list_AllCheckBox);
chk_Cart_list_AllCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
// TODO 自动生成的方法存根
for (int i = 0; i < CartList.get(fCurrentIndex).getCartProductList().size(); i++)
{
if(isChecked)
{
CartList.get(fCurrentIndex).getCartProductList().get(i).setIsCheck(true);
}else {
CartList.get(fCurrentIndex).getCartProductList().get(i).setIsCheck(false);
}
}
cartProductAdapter.notifyDataSetChanged();
}
});
cartProductAdapter=new CartProductAdapter(context, CartList.get(fCurrentIndex).getCartProductList(),mHandler);
lv_Cart_List_Product.setAdapter(cartProductAdapter);
return convertView;
5.商品明细适配器 中的Getview
viewHolder.txtTextViewName.setText(CartProductlist.get(position).getfItemName());
viewHolder.txtTextViewPrice.setText(" ¥ "+CartProductlist.get(position).getfSalePrice());
viewHolder.editTextQty.setText(CartProductlist.get(position).getfQty()+"");
viewHolder.checkBoxIsCheck.setTag(CartProductlist.get(position).getfItemID());
if(CartProductlist.get(position).getIsCheck())
{
viewHolder.checkBoxIsCheck.setChecked(true);
}else {
viewHolder.checkBoxIsCheck.setChecked(false);
}
现已经实现了 点击结算的全选,所有的卖家CheckBox 都能全选,全不选,但是在 点击卖家的CHeckBox 操作当前卖家下的商品明细全选 反选 不起作用.请做过的给思路或者给解决办法,包括后面的 全选 ,卖家全选,单选卖家改为不全选。计算价格的改变
等