<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<!-- 列表分割线 色值#999999 -->
<color name="list_divider">#999999</color>
<!-- 选中态色块 色值#D7D7D7 -->
<color name="list_item_pressed">#D7D7D7</color>
<color name="white">#ffffff</color>
<!-- 白色 -->
<color name="ivory">#fffff0</color>
<!-- 象牙色 -->
<color name="lightyellow">#ffffe0</color>
<color name="capture_text_cover_bg">#3060a4e3</color>
<!-- 亮黄色 -->
<color name="yellow">#ffff00</color>
<!-- 黄色 -->
<color name="snow">#fffafa</color>
<!-- 雪白色 -->
<color name="floralwhite">#fffaf0</color>
<!-- 花白色 -->
<color name="lemonchiffon">#fffacd</color>
<!-- 柠檬绸色 -->
<color name="cornsilk">#fff8dc</color>
<!-- 米绸色 -->
<color name="seaShell">#fff5ee</color>
<!-- 海贝色 -->
<color name="lavenderblush">#fff0f5</color>
<!-- 淡紫红 -->
<color name="papayawhip">#ffefd5</color>
<!-- 番木色 -->
<color name="blanchedalmond">#ffebcd</color>
<!-- 白杏色 -->
<color name="mistyrose">#ffe4e1</color>
<!-- 浅玫瑰色 -->
<color name="bisque">#ffe4c4</color>
<!-- 桔黄色 -->
<color name="moccasin">#ffe4b5</color>
<!-- 鹿皮色 -->
<color name="navajowhite">#ffdead</color>
<!-- 纳瓦白 -->
<color name="peachpuff">#ffdab9</color>
<!-- 桃色 -->
<color name="gold">#ffd700</color>
<!-- 金色 -->
<color name="pink">#ffc0cb</color>
<!-- 粉红色 -->
<color name="lightpink">#ffb6c1</color>
<!-- 亮粉红色 -->
<color name="orange">#fd7903</color>
<!-- 橙色 -->
<color name="lightsalmon">#ffa07a</color>
<!-- 亮肉色 -->
<color name="darkorange">#ff8c00</color>
<!-- 暗桔黄色 -->
<color name="coral">#ff7f50</color>
<!-- 珊瑚色 -->
<color name="hotpink">#ff69b4</color>
<!-- 热粉红色 -->
<color name="tomato">#ff6347</color>
<!-- 西红柿色 -->
<color name="orangered">#ff4500</color>
<!-- 红橙色 -->
<color name="deeppink">#ff1493</color>
<!-- 深粉红色 -->
<color name="fuchsia">#ff00ff</color>
<!-- 紫红色 -->
<color name="magenta">#ff00ff</color>
<!-- 红紫色 -->
<color name="red">#ff0000</color>
<!-- 红色 -->
<color name="oldlace">#fdf5e6</color>
<!-- 老花色 -->
<color name="lightgoldenrodyellow">#fafad2</color>
<!-- 亮金黄色 -->
<color name="linen">#faf0e6</color>
<!-- 亚麻色 -->
<color name="antiquewhite">#faebd7</color>
<!-- 古董白 -->
<color name="salmon">#fa8072</color>
<!-- 鲜肉色 -->
<color name="ghostwhite">#f8f8ff</color>
<!-- 幽灵白 -->
<color name="mintcream">#f5fffa</color>
<!-- 薄荷色 -->
<color name="whitesmoke">#f5f5f5</color>
<!-- 烟白色 -->
<color name="beige">#f5f5dc</color>
<!-- 米色 -->
<color name="wheat">#f5deb3</color>
<!-- 浅黄色 -->
<color name="sandybrown">#f4a460</color>
<!-- 沙褐色 -->
<color name="azure">#f0ffff</color>
<!-- 天蓝色 -->
<color name="honeydew">#f0fff0</color>
<!-- 蜜色 -->
<color name="aliceblue">#f0f8ff</color>
<!-- 艾利斯兰 -->
<color name="khaki">#f0e68c</color>
<!-- 黄褐色 -->
<color name="lightcoral">#f08080</color>
<!-- 亮珊瑚色 -->
<color name="palegoldenrod">#eee8aa</color>
<!-- 苍麒麟色 -->
<color name="violet">#ee82ee</color>
<!-- 紫罗兰色 -->
<color name="darksalmon">#e9967a</color>
<!-- 暗肉色 -->
<color name="lavender">#e6e6fa</color>
<!-- 淡紫色 -->
<color name="lightcyan">#e0ffff</color>
<!-- 亮青色 -->
<color name="burlywood">#deb887</color>
<!-- 实木色 -->
<color name="plum">#dda0dd</color>
<!-- 洋李色 -->
<color name="gainsboro">#dcdcdc</color>
<!-- 淡灰色 -->
<color name="crimson">#dc143c</color>
<!-- 暗深红色 -->
<color name="palevioletred">#db7093</color>
<!-- 苍紫罗兰色 -->
<color name="goldenrod">#daa520</color>
<!-- 金麒麟色 -->
<color name="orchid">#da70d6</color>
<!-- 淡紫色 -->
<color name="thistle">#d8bfd8</color>
<!-- 蓟色 -->
<color name="lightgray">#d3d3d3</color>
<!-- 亮灰色 -->
<color name="lightgrey">#d3d3d3</color>
<!-- 亮灰色 -->
<color name="tan">#d2b48c</color>
<!-- 茶色 -->
<color name="chocolate">#d2691e</color>
<!-- 巧可力色 -->
<color name="peru">#cd853f</color>
<!-- 秘鲁色 -->
<color name="indianred">#cd5c5c</color>
<!-- 印第安红 -->
<color name="mediumvioletred">#c71585</color>
<!-- 中紫罗兰色 -->
<color name="silver">#c0c0c0</color>
<!-- 银色 -->
<color name="darkkhaki">#bdb76b</color>
<!-- 暗黄褐色 -->
<color name="rosybrown">#bc8f8f</color>
<!-- 褐玫瑰红 -->
<color name="mediumorchid">#ba55d3</color>
<!-- 中粉紫色 -->
<color name="darkgoldenrod">#b8860b</color>
<!-- 暗金黄色 -->
<color name="firebrick">#b22222</color>
<!-- 火砖色 -->
<color name="powderblue">#b0e0e6</color>
<!-- 粉蓝色 -->
<color name="lightsteelblue">#b0c4de</color>
<!-- 亮钢兰色 -->
<color name="paleturquoise">#afeeee</color>
<!-- 苍宝石绿 -->
<color name="greenyellow">#adff2f</color>
<!-- 黄绿色 -->
<color name="lightblue">#add8e6</color>
<!-- 亮蓝色 -->
<color name="darkgray">#a9a9a9</color>
<!-- 暗灰色 -->
<color name="darkgrey">#a9a9a9</color>
<!-- 暗灰色 -->
<color name="brown">#a52a2a</color>
<!-- 褐色 -->
<color name="sienna">#a0522d</color>
<!-- 赭色 -->
<color name="darkorchid">#9932cc</color>
<!-- 暗紫色 -->
<color name="palegreen">#98fb98</color>
<!-- 苍绿色 -->
<color name="darkviolet">#9400d3</color>
<!-- 暗紫罗兰色 -->
<color name="mediumpurple">#9370db</color>
<!-- 中紫色 -->
<color name="lightgreen">#90ee90</color>
<!-- 亮绿色 -->
<color name="darkseagreen">#8fbc8f</color>
<!-- 暗海兰色 -->
<color name="saddlebrown">#8b4513</color>
<!-- 重褐色 -->
<color name="darkmagenta">#8b008b</color>
<!-- 暗洋红 -->
<color name="darkred">#8b0000</color>
<!-- 暗红色 -->
<color name="blueviolet">#8a2be2</color>
<!-- 紫罗兰蓝色 -->
<color name="lightskyblue">#87cefa</color>
<!-- 亮天蓝色 -->
<color name="skyblue">#87ceeb</color>
<!-- 天蓝色 -->
<color name="gray">#808080</color>
<!-- 灰色 -->
<color name="grey">#7c7b7b</color>
<!-- 灰色 -->
<color name="olive">#808000</color>
<!-- 橄榄色 -->
<color name="purple">#800080</color>
<!-- 紫色 -->
<color name="maroon">#800000</color>
<!-- 粟色 -->
<color name="aquamarine">#7fffd4</color>
<!-- 碧绿色 -->
<color name="chartreuse">#7fff00</color>
<!-- 黄绿色 -->
<color name="lawngreen">#7cfc00</color>
<!-- 草绿色 -->
<color name="mediumslateblue">#7b68ee</color>
<!-- 中暗蓝色 -->
<color name="lightslategray">#778899</color>
<!-- 亮蓝灰 -->
<color name="lightslategrey">#778899</color>
<!-- 亮蓝灰 -->
<color name="slategray">#708090</color>
<!-- 灰石色 -->
<color name="slategrey">#708090</color>
<!-- 灰石色 -->
<color name="olivedrab">#6b8e23</color>
<!-- 深绿褐色 -->
<color name="slateblue">#6a5acd</color>
<!-- 石蓝色 -->
<color name="dimgray">#696969</color>
<!-- 暗灰色 -->
<color name="dimgrey">#696969</color>
<!-- 暗灰色 -->
<color name="mediumaquamarine">#66cdaa</color>
<!-- 中绿色 -->
<color name="cornflowerblue">#6495ed</color>
<!-- 菊兰色 -->
<color name="cadetblue">#5f9ea0</color>
<!-- 军兰色 -->
<color name="darkolivegreen">#556b2f</color>
<!-- 暗橄榄绿 -->
<color name="indigo">#4b0082</color>
<!-- 靛青色 -->
<color name="mediumturquoise">#48d1cc</color>
<!-- 中绿宝石 -->
<color name="darkslateblue">#483d8b</color>
<!-- 暗灰蓝色 -->
<color name="steelblue">#4682b4</color>
<!-- 钢兰色 -->
<color name="royalblue">#4169e1</color>
<!-- 皇家蓝 -->
<color name="turquoise">#40e0d0</color>
<!-- 青绿色 -->
<color name="mediumseagreen">#3cb371</color>
<!-- 中海蓝 -->
<color name="limegreen">#32cd32</color>
<!-- 橙绿色 -->
<color name="darkslategray">#2f4f4f</color>
<!-- 暗瓦灰色 -->
<color name="darkslategrey">#2f4f4f</color>
<!-- 暗瓦灰色 -->
<color name="seagreen">#2e8b57</color>
<!-- 海绿色 -->
<color name="forestgreen">#228b22</color>
<!-- 森林绿 -->
<color name="lightseagreen">#20b2aa</color>
<!-- 亮海蓝色 -->
<color name="dodgerblue">#1e90ff</color>
<!-- 闪兰色 -->
<color name="midnightblue">#191970</color>
<!-- 中灰兰色 -->
<color name="aqua">#00ffff</color>
<!-- 浅绿色 -->
<color name="cyan">#00ffff</color>
<!-- 青色 -->
<color name="springgreen">#00ff7f</color>
<!-- 春绿色 -->
<color name="lime">#00ff00</color>
<!-- 酸橙色 -->
<color name="mediumspringgreen">#00fa9a</color>
<!-- 中春绿色 -->
<color name="darkturquoise">#00ced1</color>
<!-- 暗宝石绿 -->
<color name="deepskyblue">#00bfff</color>
<!-- 深天蓝色 -->
<color name="darkcyan">#008b8b</color>
<!-- 暗青色 -->
<color name="teal">#008080</color>
<!-- 水鸭色 -->
<color name="green">#008000</color>
<!-- 绿色 -->
<color name="darkgreen">#006400</color>
<!-- 暗绿色 -->
<color name="blue">#005dc1</color>
<!-- 蓝色 -->
<color name="mediumblue">#0000cd</color>
<!-- 中兰色 -->
<color name="darkblue">#00008b</color>
<!-- 暗蓝色 -->
<color name="navy">#000080</color>
<!-- 海军色 -->
<color name="black">#3B3B3B</color>
<!-- 黑色 -->
<!-- #2b4f6d 退改签 、选择配送信息中地址 文字的颜色值 -->
<!-- 通用颜色统一风格 -->
<color name="text_click">#0174E1</color>
<color name="table_background">#cbcbcb</color>
<color name="background">#eaeaea</color>
<color name="light_white">#fcfcfc</color>
<color name="tab_main_color">#1e1d1d</color>
<color name="comm_bg">#eaeaea</color>
<!-- 加黑 -->
<color name="comm_text_black">#464646</color>
<!-- 常用左侧文字颜色 -->
<color name="comm_text_left">#3c3c3c</color>
<!-- 常用右侧文字颜色 -->
<color name="comm_text_right">#3c3c3c</color>
<color name="comm_text_red">#da1609</color>
<color name="comm_text_blue">#0f90e3</color>
<color name="comm_text_green">#66c058</color>
<color name="comm_text_yellow">#DAE532</color>
<color name="comm_button_blue">#0074E1</color>
<!-- 常用提示文字颜色 -->
<color name="comm_text_tips">#949494</color>
<!-- 分割线颜色 -->
<color name="comm_cutline">#c4c4c4</color>
<!-- 内容条目按下时的样式 -->
<color name="pressed_bg">#f2f2f2</color>
<color name="nopressed_bg">#fff</color>
<!-- 助手内容颜色 -->
<color name="title_content_color">#484848</color>
<color name="content_color">#7d7d7d</color>
<!-- 理财 -->
<color name="new_red">#D21A3E</color>
<color name="new_red_press">#B41131</color>
<color name="text_black">#515151</color>
<color name="text_left">#646464</color>
<color name="text_right">#a1a1a1</color>
<color name="text_gray">#b5b5b5</color>
<color name="cutline_gray">#c4c4c4</color>
<color name="text_yellow">#b18500</color>
<color name="btn_bg_gray">#f7f7f7</color>
<color name="new_green">#00FF99</color>
<!-- 首页快捷菜单 -->
<color name="menu_item_bg">#f6f6f6</color>
<color name="text_tips">#929292</color>
<!-- 账户总览 -->
<color name="text_left_account">#464646</color>
<color name="text_bom_account">#464646</color>
<!-- 品质生活 商品列表 -->
<color name="text_price_red">#ed3b3b</color>
<color name="text_sold_greay">#b0b0b0</color>
<color name="text_title_black">#232323</color>
<!-- 帮助中心-常见问题 -->
<color name="text_question">#333333</color>
<color name="text_answer">#777777</color>
<color name="result_view">#b0000000</color>
<color name="viewfinder_mask">#60000000</color>
<color name="possible_result_points">#c0ffff00</color>
<color name="transparent">#00000000</color>
<color name="comm_card_bg">#ffffff</color>
<color name="grey_50">#fafafa</color>
<color name="grey_200">#eeeeee</color>
<color name="btn_blue">#0067db</color>
<!-- 右边菜单点击颜色 -->
<color name="right_menu_unpressed">#CDCEC9</color>
<color name="right_menu_pressed">#C3C3C3</color>
<color name="menu_item_press">#2e000000</color>
<color name="page_backgroup">#f2f2f2</color>
<!-- 灰色 -->
<color name="grey_color1">#333333</color>
<color name="grey_color2">#666666</color>
<color name="grey_color3">#999999</color>
<!-- 橙色 -->
<color name="orange_color">#de6838</color>
</resources>
values:
dimens.xml <resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
strings.xml
<string name="good_count">x %d</string>
<string name="price">¥%s</string>
<string name="total_0">合计:¥0.00</string>
<string name="total">合计:¥%s</string>
<string name="jiesuan_0">结算(0)</string>
<string name="jiesuan">结算(%s)</string>
<string name="cart_title_0">购物车(0)</string>
<string name="cart_title">购物车(%s)</string>
selectr.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_launcher" android:state_checked="true"></item>
<item android:drawable="@drawable/ic_launcher_round"></item>
</selector>
代码
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.louisgeek.louisshopcart.adapter.MyBaseExpandableListAdapter;
import com.louisgeek.louisshopcart.bean.GoodsBean;
import com.louisgeek.louisshopcart.bean.StoreBean;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
//定义父列表项List数据集合
List<Map<String, Object>> parentMapList = new ArrayList<Map<String, Object>>();
//定义子列表项List数据集合
List<List<Map<String, Object>>> childMapList_list = new ArrayList<List<Map<String, Object>>>();
MyBaseExpandableListAdapter myBaseExpandableListAdapter;
CheckBox id_cb_select_all;
LinearLayout id_ll_normal_all_state;
LinearLayout id_ll_editing_all_state;
ExpandableListView expandableListView;
RelativeLayout id_rl_cart_is_empty;
RelativeLayout id_rl_foot;
TextView id_tv_edit_all;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//initData();
initCartData();
expandableListView = (ExpandableListView) findViewById(R.id.id_elv_listview);
myBaseExpandableListAdapter = new MyBaseExpandableListAdapter(this, parentMapList, childMapList_list);
expandableListView.setAdapter(myBaseExpandableListAdapter);
expandableListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "click:" + position, Toast.LENGTH_SHORT).show();
}
});
for (int i = 0; i < parentMapList.size(); i++) {
expandableListView.expandGroup(i);
}
ImageView id_iv_back = (ImageView) findViewById(R.id.id_iv_back);
id_iv_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "click :back", Toast.LENGTH_SHORT).show();
}
});
id_ll_normal_all_state = (LinearLayout) findViewById(R.id.id_ll_normal_all_state);
id_ll_editing_all_state = (LinearLayout) findViewById(R.id.id_ll_editing_all_state);
id_rl_cart_is_empty = (RelativeLayout) findViewById(R.id.id_rl_cart_is_empty);
TextView id_tv_save_star_all = (TextView) findViewById(R.id.id_tv_save_star_all);
id_tv_save_star_all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "收藏多选商品", Toast.LENGTH_SHORT).show();
}
});
TextView id_tv_delete_all = (TextView) findViewById(R.id.id_tv_delete_all);
id_tv_delete_all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myBaseExpandableListAdapter.removeGoods();
// Toast.makeText(MainActivity.this, "删除多选商品", Toast.LENGTH_SHORT).show();
}
});
id_tv_edit_all = (TextView) findViewById(R.id.id_tv_edit_all);
id_tv_edit_all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v instanceof TextView) {
TextView tv = (TextView) v;
if (MyBaseExpandableListAdapter.EDITING.equals(tv.getText())) {
myBaseExpandableListAdapter.setupEditingAll(true);
tv.setText(MyBaseExpandableListAdapter.FINISH_EDITING);
changeFootShowDeleteView(true);//这边类似的功能 后期待使用观察者模式
} else {
myBaseExpandableListAdapter.setupEditingAll(false);
tv.setText(MyBaseExpandableListAdapter.EDITING);
changeFootShowDeleteView(false);//这边类似的功能 后期待使用观察者模式
}
}
}
});
id_cb_select_all = (CheckBox) findViewById(R.id.id_cb_select_all);
/* 要么遍历判断再选择 id_cb_select_all.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Toast.makeText(MainActivity.this, "all isChecked:" + isChecked, Toast.LENGTH_SHORT).show();
myBaseExpandableListAdapter.setupAllChecked(isChecked);
}
});*/
id_cb_select_all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v instanceof CheckBox) {
CheckBox checkBox = (CheckBox) v;
myBaseExpandableListAdapter.setupAllChecked(checkBox.isChecked());
}
}
});
final TextView id_tv_totalPrice = (TextView) findViewById(R.id.id_tv_totalPrice);
final TextView id_tv_totalCount_jiesuan = (TextView) findViewById(R.id.id_tv_totalCount_jiesuan);
id_tv_totalCount_jiesuan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "click:结算", Toast.LENGTH_SHORT).show();
}
});
myBaseExpandableListAdapter.setOnGoodsCheckedChangeListener(new MyBaseExpandableListAdapter.OnGoodsCheckedChangeListener() {
@Override
public void onGoodsCheckedChange(int totalCount, double totalPrice) {
id_tv_totalPrice.setText(String.format(getString(R.string.total), totalPrice));
id_tv_totalCount_jiesuan.setText(String.format(getString(R.string.jiesuan), totalCount));
}
});
myBaseExpandableListAdapter.setOnAllCheckedBoxNeedChangeListener(new MyBaseExpandableListAdapter.OnAllCheckedBoxNeedChangeListener() {
@Override
public void onCheckedBoxNeedChange(boolean allParentIsChecked) {
id_cb_select_all.setChecked(allParentIsChecked);
}
});
myBaseExpandableListAdapter.setOnEditingTvChangeListener(new MyBaseExpandableListAdapter.OnEditingTvChangeListener() {
@Override
public void onEditingTvChange(boolean allIsEditing) {
changeFootShowDeleteView(allIsEditing);//这边类似的功能 后期待使用观察者模式
}
});
myBaseExpandableListAdapter.setOnCheckHasGoodsListener(new MyBaseExpandableListAdapter.OnCheckHasGoodsListener() {
@Override
public void onCheckHasGoods(boolean isHasGoods) {
setupViewsShow(isHasGoods);
}
});
/**====include进来方式可能会导致view覆盖listview的最后一个item 解决*/
//在onCreate方法中一般没办法直接调用view.getHeight方法来获取到控件的高度
id_rl_foot = (RelativeLayout) findViewById(R.id.id_rl_foot);
int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
id_rl_foot.measure(w, h);
int r_width = id_rl_foot.getMeasuredWidth();
int r_height = id_rl_foot.getMeasuredHeight();
Log.i("MeasureSpec", "MeasureSpec r_width = " + r_width);
Log.i("MeasureSpec", "MeasureSpec r_height = " + r_height);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
int top = dp2px(this, 48);
lp.setMargins(0, top, 0, r_height);//48
expandableListView.setLayoutParams(lp);
/**==========*/
if (parentMapList != null && parentMapList.size() > 0) {
setupViewsShow(true);
} else {
setupViewsShow(false);
}
/* *//**
* 第一个参数 应用程序接口 this
* 第二个父列List<?extends Map<String,Object>>集合 为父列提供数据
* 第三个参数 父列显示的组件资源文件
* 第四个参数 键值列表 父列Map字典的key
* 第五个要显示的父列组件id
* 第六个 子列的显示资源文件
* 第七个参数 键值列表的子列Map字典的key
* 第八个要显示子列的组件id
*
* 第五个参数groupTo - The group views that should display column in the "groupFrom" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the groupFrom parameter.
*//*
SimpleExpandableListAdapter simpleExpandableListAdapter = new SimpleExpandableListAdapter(
this, parentMapList, R.layout.parent_layout, new String[] { "parentName"},
new int[] { R.id.tv_title_parent}, childMapList_list, R.layout.child_layout,
new String[] { "childName"}, new int[] { R.id.tv_items_child});
expandableListView.setAdapter(simpleExpandableListAdapter);*/
}
private void setupViewsShow(boolean isHasGoods) {
if (isHasGoods) {
expandableListView.setVisibility(View.VISIBLE);
id_rl_cart_is_empty.setVisibility(View.GONE);
id_rl_foot.setVisibility(View.VISIBLE);
id_tv_edit_all.setVisibility(View.VISIBLE);
} else {
expandableListView.setVisibility(View.GONE);
id_rl_cart_is_empty.setVisibility(View.VISIBLE);
id_rl_foot.setVisibility(View.GONE);
id_tv_edit_all.setVisibility(View.GONE);
}
}
public void changeFootShowDeleteView(boolean showDeleteView) {
if (showDeleteView) {
id_tv_edit_all.setText(MyBaseExpandableListAdapter.FINISH_EDITING);
id_ll_normal_all_state.setVisibility(View.INVISIBLE);
id_ll_editing_all_state.setVisibility(View.VISIBLE);
} else {
id_tv_edit_all.setText(MyBaseExpandableListAdapter.EDITING);
id_ll_normal_all_state.setVisibility(View.VISIBLE);
id_ll_editing_all_state.setVisibility(View.INVISIBLE);
}
}
public int dp2px(Context context, float dp) {
float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
private void initCartData() {
for (int i = 0; i < 4; i++) {
String store="旗舰店";
if(i%2==0){
store="专营店";
}
//提供父列表的数据
Map<String, Object> parentMap = new HashMap<String, Object>();
parentMap.put("parentName", new StoreBean("" + i, store + i, false, false));
/* if (i%2==0) {
parentMap.put("parentIcon", R.mipmap.ic_launcher);
}else
{
parentMap.put("parentIcon", R.mipmap.louisgeek);
}*/
parentMapList.add(parentMap);
//提供当前父列的子列数据
List<Map<String, Object>> childMapList = new ArrayList<Map<String, Object>>();
for (int j = 0; j < 3; j++) {
Map<String, Object> childMap = new HashMap<String, Object>();
GoodsBean goodsBean = new GoodsBean(i + "_" + j, store+i + "下的商品" + j, "url", "均码,红色", 150, 120, 1, GoodsBean.STATUS_VALID, false, false);
childMap.put("childName", goodsBean);
childMapList.add(childMap);
}
childMapList_list.add(childMapList);
}
}
private void initData() {
for (int i = 0; i < 15; i++) {
//提供父列表的数据
Map<String, Object> parentMap = new HashMap<String, Object>();
parentMap.put("parentName", "parentName" + i);
if (i % 2 == 0) {
parentMap.put("parentIcon", R.mipmap.ic_launcher);
} else {
parentMap.put("parentIcon", R.mipmap.louisgeek);
}
parentMapList.add(parentMap);
//提供当前父列的子列数据
List<Map<String, Object>> childMapList = new ArrayList<Map<String, Object>>();
for (int j = 0; j < 10; j++) {
Map<String, Object> childMap = new HashMap<String, Object>();
childMap.put("childName", "parentName" + i + "下面的childName" + j);
childMapList.add(childMap);
}
childMapList_list.add(childMapList);
}
}
}
import android.content.Context;
import android.graphics.Paint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.louisgeek.louisshopcart.R;
import com.louisgeek.louisshopcart.bean.GoodsBean;
import com.louisgeek.louisshopcart.bean.StoreBean;
import java.util.List;
import java.util.Map;
/**
* Created by louisgeek on 2016/4/27.
*/
public class MyBaseExpandableListAdapter extends BaseExpandableListAdapter {
private static final String TAG = "MyBaseEtAdapter";
List<Map<String, Object>> parentMapList;
List<List<Map<String, Object>>> childMapList_list;
Context context;
int totalCount = 0;
double totalPrice = 0.00;
public static final String EDITING = "编辑";
public static final String FINISH_EDITING = "完成";
OnAllCheckedBoxNeedChangeListener onAllCheckedBoxNeedChangeListener;
OnGoodsCheckedChangeListener onGoodsCheckedChangeListener;
OnCheckHasGoodsListener onCheckHasGoodsListener;
public void setOnCheckHasGoodsListener(OnCheckHasGoodsListener onCheckHasGoodsListener) {
this.onCheckHasGoodsListener = onCheckHasGoodsListener;
}
public void setOnEditingTvChangeListener(OnEditingTvChangeListener onEditingTvChangeListener) {
this.onEditingTvChangeListener = onEditingTvChangeListener;
}
OnEditingTvChangeListener onEditingTvChangeListener;
public void setOnGoodsCheckedChangeListener(OnGoodsCheckedChangeListener onGoodsCheckedChangeListener) {
this.onGoodsCheckedChangeListener = onGoodsCheckedChangeListener;
}
public void setOnAllCheckedBoxNeedChangeListener(OnAllCheckedBoxNeedChangeListener onAllCheckedBoxNeedChangeListener) {
this.onAllCheckedBoxNeedChangeListener = onAllCheckedBoxNeedChangeListener;
}
public MyBaseExpandableListAdapter(Context context, List<Map<String, Object>> parentMapList, List<List<Map<String, Object>>> childMapList_list) {
this.parentMapList = parentMapList;
this.childMapList_list = childMapList_list;
this.context = context;
}
//获取当前父item的数据数量
@Override
public int getGroupCount() {
return parentMapList.size();
}
//获取当前父item下的子item的个数
@Override
public int getChildrenCount(int groupPosition) {
return childMapList_list.get(groupPosition).size();
}
//获取当前父item的数据
@Override
public Object getGroup(int groupPosition) {
return parentMapList.get(groupPosition);
}
//得到子item需要关联的数据
@Override
public Object getChild(int groupPosition, int childPosition) {
return childMapList_list.get(groupPosition).get(childPosition);
}
//得到父item的ID
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
//得到子item的ID
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
//return false;
return true;
}
//设置父item组件
@Override
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
GroupViewHolder groupViewHolder = null;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.parent_layout, null);
groupViewHolder = new GroupViewHolder();
groupViewHolder.tv_title_parent = (TextView) convertView
.findViewById(R.id.tv_title_parent);
groupViewHolder.id_tv_edit = (TextView) convertView
.findViewById(R.id.id_tv_edit);
groupViewHolder.id_cb_select_parent = (CheckBox) convertView
.findViewById(R.id.id_cb_select_parent);
convertView.setTag(groupViewHolder);
} else {
groupViewHolder = (GroupViewHolder) convertView.getTag();
}
StoreBean storeBean = (StoreBean) parentMapList.get(groupPosition).get("parentName");
final String parentName = storeBean.getName();
groupViewHolder.tv_title_parent.setText(parentName);
if (storeBean.isEditing()) {
groupViewHolder.id_tv_edit.setText(FINISH_EDITING);
} else {
groupViewHolder.id_tv_edit.setText(EDITING);
}
groupViewHolder.id_tv_edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text = "";
TextView textView = null;
if (v instanceof TextView) {
textView = (TextView) v;
}
// Toast.makeText(context, "编辑:" + groupPosition, Toast.LENGTH_SHORT).show();
textView.setText(text);
setupEditing(groupPosition);
onEditingTvChangeListener.onEditingTvChange(dealAllEditingIsEditing());
}
});
//覆盖原有收起展开事件
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "店铺:" + parentName, Toast.LENGTH_SHORT).show();
}
});
groupViewHolder.id_cb_select_parent.setChecked(storeBean.isChecked());
final boolean nowBeanChecked = storeBean.isChecked();
groupViewHolder.id_cb_select_parent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setupOneParentAllChildChecked(!nowBeanChecked, groupPosition);
//控制总checkedbox 接口
onAllCheckedBoxNeedChangeListener.onCheckedBoxNeedChange(dealAllParentIsChecked());
}
});
//遍历改变也会触发这个方法
/* groupViewHolder.id_cb_select_parent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
boolean allParentIsChecked=dealAllParentIsChecked();
Log.d(TAG, "=====onCheckedChanged: ==============");
Log.d(TAG, "=====onCheckedChanged: allParentIsChecked:"+allParentIsChecked);
Log.d(TAG, "=====onCheckedChanged: groupPosition:"+groupPosition);
Log.d(TAG, "=====onCheckedChanged: isChecked:" + isChecked);
//Toast.makeText(context, "allParentIsChecked!!! isChecked:"+groupPosition+"=" + isChecked, Toast.LENGTH_SHORT).show();
//控制总checkedbox 接口
onAllCheckedBoxChangeListener.OnCheckedBoxChange(allParentIsChecked);
});*/
/*ImageView iv_img_parent=(ImageView)convertView.findViewById(R.id.iv_img_parent);
int parentIcon = Integer.parseInt(parentMapList.get(groupPosition).get("parentIcon").toString());
iv_img_parent.setImageResource(parentIcon);*/
/* ImageView iv_img_parent_right=(ImageView)convertView.findViewById(R.id.iv_img_parent_right);
//判断isExpanded就可以控制是按下还是关闭,同时更换图片
if(isExpanded){
iv_img_parent_right.setImageResource(R.mipmap.channel_expandablelistview_top_icon);
}else{
iv_img_parent_right.setImageResource(R.mipmap.channel_expandablelistview_bottom_icon);
}*/
return convertView;
}
//设置子item的组件
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildViewHolder childViewHolder = null;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.child_layout, null);
childViewHolder = new ChildViewHolder();
childViewHolder.tv_items_child = (TextView) convertView
.findViewById(R.id.tv_items_child);
childViewHolder.id_cb_select_child = (CheckBox) convertView
.findViewById(R.id.id_cb_select_child);
childViewHolder.id_ll_normal = (LinearLayout) convertView
.findViewById(R.id.id_ll_normal);
childViewHolder.id_ll_edtoring = (LinearLayout) convertView
.findViewById(R.id.id_ll_edtoring);
//常规下:
childViewHolder.tv_items_child_desc = (TextView) convertView
.findViewById(R.id.tv_items_child_desc);
childViewHolder.id_tv_price = (TextView) convertView
.findViewById(R.id.id_tv_price);
childViewHolder.id_tv_discount_price = (TextView) convertView
.findViewById(R.id.id_tv_discount_price);
childViewHolder.id_tv_count = (TextView) convertView
.findViewById(R.id.id_tv_count);
//编辑下:
childViewHolder.id_iv_reduce = (ImageView) convertView
.findViewById(R.id.id_iv_reduce);
childViewHolder.id_iv_add = (ImageView) convertView
.findViewById(R.id.id_iv_add);
childViewHolder.id_tv_count_now = (TextView) convertView
.findViewById(R.id.id_tv_count_now);
childViewHolder.id_tv_price_now = (TextView) convertView
.findViewById(R.id.id_tv_price_now);
childViewHolder.id_tv_des_now = (TextView) convertView
.findViewById(R.id.id_tv_des_now);
childViewHolder.id_tv_goods_star = (TextView) convertView
.findViewById(R.id.id_tv_goods_star);
childViewHolder.id_tv_goods_delete = (TextView) convertView
.findViewById(R.id.id_tv_goods_delete);
convertView.setTag(childViewHolder);
} else {
childViewHolder = (ChildViewHolder) convertView.getTag();
}
final GoodsBean goodsBean = (GoodsBean) childMapList_list.get(groupPosition).get(childPosition).get("childName");
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "商品:" + goodsBean.getName(), Toast.LENGTH_SHORT).show();
}
});
childViewHolder.tv_items_child.setText(goodsBean.getName());
childViewHolder.id_tv_price.setText(String.format(context.getString(R.string.price), goodsBean.getPrice()));
// childViewHolder.id_tv_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//数字划线效果
childViewHolder.id_tv_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); // 设置中划线并抗锯齿
childViewHolder.id_tv_discount_price.setText(String.format(context.getString(R.string.price), goodsBean.getDiscountPrice()));
childViewHolder.tv_items_child_desc.setText(String.valueOf(goodsBean.getDesc()));
childViewHolder.id_tv_count.setText(String.format(context.getString(R.string.good_count), goodsBean.getCount()));
childViewHolder.id_tv_count_now.setText(String.valueOf(goodsBean.getCount()));
double priceNow = goodsBean.getCount() * goodsBean.getDiscountPrice();//小结
childViewHolder.id_tv_price_now.setText(String.format(context.getString(R.string.price), priceNow));
childViewHolder.id_tv_des_now.setText(goodsBean.getDesc());
childViewHolder.id_cb_select_child.setChecked(goodsBean.isChecked());
childViewHolder.id_cb_select_child.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final boolean nowBeanChecked = goodsBean.isChecked();
//更新数据
goodsBean.setIsChecked(!nowBeanChecked);
boolean isOneParentAllChildIsChecked = dealOneParentAllChildIsChecked(groupPosition);
Log.d(TAG, "getChildView:onClick: ==============");
Log.d(TAG, "getChildView:onClick:isOneParentAllChildIsChecked:" + isOneParentAllChildIsChecked);
StoreBean storeBean = (StoreBean) parentMapList.get(groupPosition).get("parentName");
storeBean.setIsChecked(isOneParentAllChildIsChecked);
notifyDataSetChanged();
//控制总checkedbox 接口
onAllCheckedBoxNeedChangeListener.onCheckedBoxNeedChange(dealAllParentIsChecked());
dealPrice();
}
});
if (goodsBean.isEditing()) {
childViewHolder.id_ll_normal.setVisibility(View.GONE);
childViewHolder.id_ll_edtoring.setVisibility(View.VISIBLE);
} else {
childViewHolder.id_ll_normal.setVisibility(View.VISIBLE);
childViewHolder.id_ll_edtoring.setVisibility(View.GONE);
}
childViewHolder.id_iv_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TextView textView= (TextView) v.getRootView().findViewById(R.id.id_tv_num);
dealAdd(goodsBean);
}
});
childViewHolder.id_iv_reduce.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TextView textView= (TextView) v.getRootView().findViewById(R.id.id_tv_num);
dealReduce(goodsBean);
}
});
childViewHolder.id_tv_goods_star.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "收藏商品:" + goodsBean.getName(), Toast.LENGTH_SHORT).show();
}
});
childViewHolder.id_tv_goods_delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(context, "删除商品:" + goodsBean.getName(), Toast.LENGTH_SHORT).show();
removeOneGood(groupPosition, childPosition);
}
});
/* id_cb_select_child.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
GoodsBean goodsBean = (GoodsBean) childMapList_list.get(groupPosition).get(childPosition).get("childName");
//更新数据
goodsBean.setIsChecked(isChecked);
boolean isAllChecked=dealOneParentAllChildIsChecked(groupPosition,isChecked);
if (isAllChecked){
StoreBean storeBean= (StoreBean) parentMapList.get(groupPosition).get("parentName");
storeBean.setIsChecked(true);
}
Toast.makeText(context, "CHALID :isAllChecked" + isAllChecked, Toast.LENGTH_SHORT).show();
notifyDataSetChanged();
}
});*/
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// return false;
return true;
}
//供全选按钮调用
public void setupAllChecked(boolean isChecked) {
Log.d(TAG, "setupAllChecked: ============");
Log.d(TAG, "setupAllChecked: isChecked:" + isChecked);
for (int i = 0; i < parentMapList.size(); i++) {
StoreBean storeBean = (StoreBean) parentMapList.get(i).get("parentName");
storeBean.setIsChecked(isChecked);
List<Map<String, Object>> childMapList = childMapList_list.get(i);
for (int j = 0; j < childMapList.size(); j++) {
GoodsBean goodsBean = (GoodsBean) childMapList.get(j).get("childName");
goodsBean.setIsChecked(isChecked);
}
}
notifyDataSetChanged();
dealPrice();
}
private void setupOneParentAllChildChecked(boolean isChecked, int groupPosition) {
Log.d(TAG, "setupOneParentAllChildChecked: ============");
Log.d(TAG, "setupOneParentAllChildChecked: groupPosition:" + groupPosition);
Log.d(TAG, "setupOneParentAllChildChecked: isChecked:" + isChecked);
StoreBean storeBean = (StoreBean) parentMapList.get(groupPosition).get("parentName");
storeBean.setIsChecked(isChecked);
List<Map<String, Object>> childMapList = childMapList_list.get(groupPosition);
for (int j = 0; j < childMapList.size(); j++) {
GoodsBean goodsBean = (GoodsBean) childMapList.get(j).get("childName");
goodsBean.setIsChecked(isChecked);
}
notifyDataSetChanged();
dealPrice();
}
public boolean dealOneParentAllChildIsChecked(int groupPosition) {
Log.d(TAG, "dealOneParentAllChildIsChecked: ============");
Log.d(TAG, "dealOneParentAllChildIsChecked: groupPosition:" + groupPosition);
// StoreBean storeBean= (StoreBean) parentMapList.get(groupPosition).get("parentName");
List<Map<String, Object>> childMapList = childMapList_list.get(groupPosition);
for (int j = 0; j < childMapList.size(); j++) {
GoodsBean goodsBean = (GoodsBean) childMapList.get(j).get("childName");
if (!goodsBean.isChecked()) {
return false;//如果有一个没选择 就false
}
}
return true;
}
public boolean dealAllParentIsChecked() {
Log.d(TAG, "dealAllParentIsChecked: ============");
for (int i = 0; i < parentMapList.size(); i++) {
StoreBean storeBean = (StoreBean) parentMapList.get(i).get("parentName");
if (!storeBean.isChecked()) {
return false;//如果有一个没选择 就false
}
}
return true;
}
public void dealPrice() {
// showList();
totalCount = 0;
totalPrice = 0.00;
for (int i = 0; i < parentMapList.size(); i++) {
//StoreBean storeBean= (StoreBean) parentMapList.get(i).get("parentName");
List<Map<String, Object>> childMapList = childMapList_list.get(i);
for (int j = 0; j < childMapList.size(); j++) {
GoodsBean goodsBean = (GoodsBean) childMapList.get(j).get("childName");
int count = goodsBean.getCount();
double discountPrice = goodsBean.getDiscountPrice();
if (goodsBean.isChecked()) {
totalCount++;//单品多数量只记1
totalPrice += discountPrice * count;
}
}
}
//计算回调
onGoodsCheckedChangeListener.onGoodsCheckedChange(totalCount, totalPrice);
}
//供总编辑按钮调用
public void setupEditingAll(boolean isEditingAll) {
for (int i = 0; i < parentMapList.size(); i++) {
StoreBean storeBean = (StoreBean) parentMapList.get(i).get("parentName");
storeBean.setIsEditing(isEditingAll);
List<Map<String, Object>> childMapList = childMapList_list.get(i);
for (int j = 0; j < childMapList.size(); j++) {
GoodsBean goodsBean = (GoodsBean) childMapList.get(j).get("childName");
goodsBean.setIsEditing(isEditingAll);
}
}
notifyDataSetChanged();
}
public boolean dealAllEditingIsEditing() {
for (int i = 0; i < parentMapList.size(); i++) {
StoreBean storeBean = (StoreBean) parentMapList.get(i).get("parentName");
if (storeBean.isEditing()) {//!!!
return true;//如果有一个是编辑状态 就true
}
}
return false;
}
public void setupEditing(int groupPosition) {
StoreBean storeBean = (StoreBean) parentMapList.get(groupPosition).get("parentName");
boolean isEditing = !storeBean.isEditing();
storeBean.setIsEditing(isEditing);
List<Map<String, Object>> childMapList = childMapList_list.get(groupPosition);
for (int j = 0; j < childMapList.size(); j++) {
GoodsBean goodsBean = (GoodsBean) childMapList.get(j).get("childName");
goodsBean.setIsEditing(isEditing);
}
notifyDataSetChanged();
}
public void dealAdd(GoodsBean goodsBean) {
int count = goodsBean.getCount();
count++;
goodsBean.setCount(count);
// textView.setText(String.valueOf(count));
notifyDataSetChanged();
dealPrice();
}
public void dealReduce(GoodsBean goodsBean) {
int count = goodsBean.getCount();
if (count == 1) {
return;
}
count--;
goodsBean.setCount(count);
// textView.setText(String.valueOf(count));
notifyDataSetChanged();
dealPrice();
}
public void removeOneGood(int groupPosition, int childPosition) {
//StoreBean storeBean = (StoreBean) parentMapList.get(groupPosition).get("parentName");
List<Map<String, Object>> childMapList = childMapList_list.get(groupPosition);
// GoodsBean goodsBean = (GoodsBean) childMapList.get(childPosition).get("childName");
childMapList.remove(childPosition);
//通过子项
if (childMapList!=null&&childMapList.size()>0){
}else {
parentMapList.remove(groupPosition);
childMapList_list.remove(groupPosition);//!!!!因为parentMapList和childMapList_list是pos关联的 得保持一致
}
if (parentMapList != null && parentMapList.size() > 0) {
onCheckHasGoodsListener.onCheckHasGoods(true);//
} else {
onCheckHasGoodsListener.onCheckHasGoods(false);//
}
notifyDataSetChanged();
dealPrice();
}
public void removeGoods() {
/* for (int i = 0; i <parentMapList.size(); i++) {
StoreBean storeBean= (StoreBean) parentMapList.get(i).get("parentName");
List<Map<String, Object>> childMapList = childMapList_list.get(i);
for (int j = 0; j < childMapList.size(); j++) {
GoodsBean goodsBean = (GoodsBean) childMapList.get(j).get("childName");
Log.d(TAG, "removeGoods:============goodsBean:" + goodsBean.isChecked());
if (goodsBean.isChecked()) {
childMapList.remove(j);
j--;//!!!!!!!!!! List remove方法比较特殊 每移除一个元素以后再把pos移回来
}
}
}*/
for (int i = parentMapList.size()-1; i>=0; i--) {//倒过来遍历 remove
StoreBean storeBean= (StoreBean) parentMapList.get(i).get("parentName");
if (storeBean.isChecked()){
parentMapList.remove(i);
childMapList_list.remove(i);
}else {
List<Map<String, Object>> childMapList = childMapList_list.get(i);
for (int j = childMapList.size()-1; j >=0; j--) {//倒过来遍历 remove
GoodsBean goodsBean = (GoodsBean) childMapList.get(j).get("childName");
if (goodsBean.isChecked()) {
childMapList.remove(j);
}
}
}
}
// showList("begin###############");
/**1.不要边遍历边删除,容易出现数组越界的情况<br>
* 2.现将要删除的对象放进相应的列表容器中,待遍历完后,以removeAll的方式进行删除*/ //还是有问题
/*List<Map<String, Object>> needRemoreParentMapList = new ArrayList<>();// 待删除的组元素列表
List<List<Map<String, Object>>> needRemoreChildMapList_List = new ArrayList<>();// 待删除的 最大的
for (int i = 0; i < parentMapList.size(); i++) {
StoreBean storeBean = (StoreBean) parentMapList.get(i).get("parentName");
if(storeBean.isChecked()){
needRemoreParentMapList.add(parentMapList.get(i));
needRemoreChildMapList_List.add(childMapList_list.get(i));//!!!!因为parentMapList和childMapList_list是pos关联的 得保持一致
}
//
List<Map<String, Object>> childMapList = childMapList_list.get(i);//最大的
List<Map<String, Object>> needRemoreChildMapList = new ArrayList<>();// 待删除的子元素列表
for (int j = 0; j < childMapList.size(); j++) {
GoodsBean goodsBean = (GoodsBean) childMapList.get(j).get("childName");
if (goodsBean.isChecked()) {
needRemoreChildMapList.add(childMapList.get(j));
}
}
childMapList.removeAll(needRemoreChildMapList);//正式删除子元素 不是childMapList_list !!!
}
parentMapList.removeAll(needRemoreParentMapList);//正式删除父元素
Log.d(TAG, "removeGoods: needRemoreChildMapList_List"+needRemoreChildMapList_List);
childMapList_list.remove(needRemoreChildMapList_List);//!!!!因为parentMapList和childMapList_list是pos关联的 得保持一致
*/
//!!!!!!!!!!!!!!!删除完 状态需要重置 待思考 why?
//resetViewAfterDelete();
if (parentMapList != null && parentMapList.size() > 0) {
onCheckHasGoodsListener.onCheckHasGoods(true);//
} else {
onCheckHasGoodsListener.onCheckHasGoods(false);//
}
//showList("after@@@@@@@@@@@@@@@@@@@@@@@");
notifyDataSetChanged();//
dealPrice();//重新计算
}
private void resetViewAfterDelete() {
for (int i = 0; i < parentMapList.size(); i++) {
StoreBean storeBean = (StoreBean) parentMapList.get(i).get("parentName");
storeBean.setIsChecked(false);
storeBean.setIsEditing(false);
List<Map<String, Object>> childMapList = childMapList_list.get(i);
for (int j = 0; j < childMapList.size(); j++) {
GoodsBean goodsBean = (GoodsBean) childMapList.get(j).get("childName");
goodsBean.setIsChecked(false);
goodsBean.setIsEditing(false);
}
}
}
void showList(String tempStr) {
Log.d(TAG, "showList:"+tempStr);
for (int i = 0; i < parentMapList.size(); i++) {
StoreBean storeBean = (StoreBean) parentMapList.get(i).get("parentName");
Log.d(TAG, "showList: parentName:【" + storeBean.getName()+"】isChecked:" + storeBean.isChecked());
List<Map<String, Object>> childMapList = childMapList_list.get(i);
for (int j = 0; j < childMapList.size(); j++) {
GoodsBean goodsBean = (GoodsBean) childMapList.get(j).get("childName");
Log.d(TAG, "showList: childName:" + goodsBean.getName()+"isChecked:" + goodsBean.isChecked());
}
}
}
public interface OnAllCheckedBoxNeedChangeListener {
void onCheckedBoxNeedChange(boolean allParentIsChecked);
}
public interface OnEditingTvChangeListener {
void onEditingTvChange(boolean allIsEditing);
}
public interface OnGoodsCheckedChangeListener {
void onGoodsCheckedChange(int totalCount, double totalPrice);
}
public interface OnCheckHasGoodsListener {
void onCheckHasGoods(boolean isHasGoods);
}
class GroupViewHolder {
TextView tv_title_parent;
TextView id_tv_edit;
CheckBox id_cb_select_parent;
}
class ChildViewHolder {
TextView tv_items_child;
CheckBox id_cb_select_child;
LinearLayout id_ll_normal;
LinearLayout id_ll_edtoring;
TextView tv_items_child_desc;
TextView id_tv_price;
TextView id_tv_discount_price;
TextView id_tv_count;
ImageView id_iv_reduce;
ImageView id_iv_add;
TextView id_tv_des_now;
TextView id_tv_count_now;
TextView id_tv_price_now;
TextView id_tv_goods_star;
TextView id_tv_goods_delete;
}
}
public class StoreBean {
/** 店铺ID */
private String id;
/** 店铺名称 */
private String name;
private boolean isChecked;
private boolean isEditing;
public StoreBean(String id, String name,boolean isChecked,boolean isEditing) {
this.id = id;
this.name = name;
this.isChecked = isChecked;
this.isEditing = isEditing;
}
public StoreBean() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public boolean isEditing() {
return isEditing;
}
public void setIsEditing(boolean isEditing) {
this.isEditing = isEditing;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isChecked() {
return isChecked;
}
public void setIsChecked(boolean isChecked) {
this.isChecked = isChecked;
}
}
public class GoodsBean {
public static final int STATUS_INVALID=0;
public static final int STATUS_VALID=1;
//===============================================
private String id;
private String name;
/** 商品宣传图片 */
private String imageLogo;
/** 商品规格 */
private String desc;
/** 原价,市场价 */
private double price;
/** 现价,折扣价 */
private double discountPrice;
private int count;
/** 状态 */
private int status;
/** 是否被选中 */
private boolean isChecked;
/** 是否是编辑状态 */
private boolean isEditing;
public GoodsBean(String id, String name, String imageLogo, String desc, double price, double discountPrice, int count, int status, boolean isChecked, boolean isEditing) {
this.id = id;
this.name = name;
this.imageLogo = imageLogo;
this.desc = desc;
this.price = price;
this.discountPrice = discountPrice;
this.count = count;
this.status = status;
this.isChecked = isChecked;
this.isEditing = isEditing;
}
public GoodsBean(){
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImageLogo() {
return imageLogo;
}
public void setImageLogo(String imageLogo) {
this.imageLogo = imageLogo;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double getDiscountPrice() {
return discountPrice;
}
public void setDiscountPrice(double discountPrice) {
this.discountPrice = discountPrice;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public boolean isChecked() {
return isChecked;
}
public void setIsChecked(boolean isChecked) {
this.isChecked = isChecked;
}
public boolean isEditing() {
return isEditing;
}
public void setIsEditing(boolean isEditing) {
this.isEditing = isEditing;
}
}
public class CartBean {
/** 商品ID */
private String goodsid;
/** 店铺ID */
private String storeid;
}
布局main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include layout="@layout/header_layout"
/>
<RelativeLayout
android:id="@+id/id_rl_cart_is_empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FCFCFC"
android:gravity="center"
android:layout_marginTop="48dp"
android:visibility="gone">
<ImageView
android:id="@+id/id_rl_cart_is_empty_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@mipmap/ic_shopping_cart_empty"/>
<TextView
android:id="@+id/id_rl_cart_is_empty_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/id_rl_cart_is_empty_image"
android:layout_marginTop="10dp"
android:text="购物车为空"/>
</RelativeLayout>
<ExpandableListView
android:id="@+id/id_elv_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#ebebeb"
android:groupIndicator="@null"
android:dividerHeight="2dp"
android:footerDividersEnabled="false"
android:visibility="visible"
>
</ExpandableListView>
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
layout="@layout/foot_layout"
/>
</RelativeLayout>
布局:chlid.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#EEEEEE"
>
<!--android:focusable="false" 不占用原有View点击事件-->
<CheckBox
android:id="@+id/id_cb_select_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="@null"
android:focusable="false"
android:button="@drawable/selector_check_bg"/>
<ImageView
android:id="@+id/id_iv_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/id_cb_select_child"
android:padding="10dp"
android:src="@mipmap/ic_launcher"
/>
<LinearLayout
android:id="@+id/id_ll_normal"
android:layout_width="match_parent"
android:layout_toRightOf="@id/id_iv_logo"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible"
>
<TextView
android:id="@+id/tv_items_child"
android:padding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="商品名称"
>
</TextView>
<TextView
android:id="@+id/tv_items_child_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="颜色规格描述"
>
</TextView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
>
<TextView
android:id="@+id/id_tv_discount_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:singleLine="true"
android:text="@string/price"
android:textColor="@android:color/holo_red_light"
android:textSize="14dp"
android:textStyle="bold" />
<TextView
android:id="@+id/id_tv_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="13dp"
android:layout_toRightOf="@+id/id_tv_discount_price"
android:text="@string/price"
android:textSize="10dp"
/>
<TextView
android:id="@+id/id_tv_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:layout_alignParentRight="true"
android:text="@string/good_count"
android:textSize="12dp"
/>
</RelativeLayout>
</LinearLayout>
<!-- android:visibility="gone"-->
<LinearLayout
android:id="@+id/id_ll_edtoring"
android:layout_toRightOf="@id/id_iv_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
>
<LinearLayout
android:id="@+id/ll_change_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<ImageView
android:id="@+id/id_iv_reduce"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_reduce"
android:padding="10dp"
android:layout_gravity="center_vertical"
/>
<TextView
android:id="@+id/id_tv_count_now"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:padding="10dp"
android:singleLine="true"
android:text="1"
android:textSize="14dp" />
<ImageView
android:id="@+id/id_iv_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@mipmap/ic_add"
android:padding="10dp"
/>
</LinearLayout>
<TextView
android:id="@+id/id_tv_price_now"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:text="@string/price"
android:textColor="@android:color/holo_red_light"
android:textSize="14dp"
android:padding="10dp"
/>
<TextView
android:id="@+id/id_tv_des_now"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="@id/ll_change_num"
android:text="颜色规格描述选择"
android:paddingLeft="10dp"
android:layout_marginBottom="10dp"
android:layout_gravity="left"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:id="@+id/id_tv_goods_star"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:background="@android:color/holo_orange_light"
android:text="收藏"
android:textColor="@android:color/white"
android:padding="13dp"
android:gravity="center"
android:layout_marginRight="2dp"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:id="@+id/id_tv_goods_delete"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#ff5000"
android:text="删除"
android:textColor="@android:color/white"
android:padding="13dp"
android:gravity="center"
android:layout_gravity="center"
/>
</LinearLayout>
</RelativeLayout>
布局:foot.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_rl_foot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white">
<ImageView
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_alignParentTop="true"
android:background="#ccc"/>
<CheckBox
android:id="@+id/id_cb_select_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="@null"
android:text=" 全选"
android:button="@drawable/selector_check_bg"/>
<!-- <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/ivSelectAll"
android:text="全选"
android:textColor="#003333"
android:textSize="13sp"/>-->
<LinearLayout
android:id="@+id/id_ll_normal_all_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:visibility="visible"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/id_tv_totalPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:gravity="right"
android:text="@string/total_0"
android:textColor="#ff2600"
android:textSize="13sp"/>
<TextView
android:id="@+id/tvPostPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:gravity="right"
android:text="不含运费"
android:textColor="#666666"
android:textSize="11sp"/>
</LinearLayout>
<TextView
android:id="@+id/id_tv_totalCount_jiesuan"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ff5000"
android:gravity="center_vertical"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp"
android:text="@string/jiesuan_0"
android:textColor="#FFF"
android:textSize="16dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/id_ll_editing_all_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone"
android:layout_alignParentRight="true"
>
<TextView
android:id="@+id/id_tv_save_star_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="移到收藏夹"
android:background="@android:color/holo_orange_light"
android:paddingBottom="15dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="15dp"
android:textSize="16dp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:textColor="@color/white"
/>
<TextView
android:id="@+id/id_tv_delete_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff5000"
android:gravity="center_vertical"
android:paddingBottom="15dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="15dp"
android:layout_gravity="center_vertical"
android:textSize="16dp"
android:text="删除"
android:textColor="@color/white"
/>
</LinearLayout>
</RelativeLayout>
布局:header.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_rl_head"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@android:color/transparent"
android:orientation="vertical" >
<ImageView
android:id="@+id/id_iv_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="center_vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:src="@mipmap/ic_back" />
<TextView
android:id="@+id/id_tv_cart_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="48dp"
android:text="购物车"
android:textColor="#1a1a1a"
android:textSize="16dp" />
<TextView
android:id="@+id/id_tv_edit_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:gravity="center"
android:minHeight="48dp"
android:text="编辑"
android:textColor="#1a1a1a"
android:textSize="16dp"
android:visibility="visible" />
</RelativeLayout>
布局:parent.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/id_ll_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="horizontal" >
<!--记得去掉箭头图 在ExpandableListView中加入android:groupIndicator="@null" -->
<!-- <View
android:id="@+id/channel_line"
android:layout_width="5dp"
android:layout_height="20dp"
android:layout_marginLeft="15dp"
android:layout_gravity="center_vertical"
android:background="#79BEF7" />-->
<!--android:focusable="false" 不占用原有View点击事件-->
<CheckBox
android:id="@+id/id_cb_select_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="@null"
android:focusable="false"
android:button="@drawable/selector_check_bg"/>
<!-- <ImageView
android:id="@+id/iv_img_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:padding="5dp"
android:layout_centerVertical="true"
android:src="@mipmap/ic_shop"
android:layout_toRightOf="@id/id_cb_select"
/>-->
<TextView
android:id="@+id/tv_title_parent"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_toRightOf="@id/id_cb_select_parent"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@mipmap/shop_icon"
android:drawableRight="@mipmap/ic_right_icon"
android:drawablePadding="10dp"
/>
<!-- <ImageView
android:id="@+id/iv_img_parent_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
/>-->
<TextView
android:id="@+id/id_tv_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="编辑"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:padding="5dp"
android:layout_centerVertical="true"
/>
</RelativeLayout>