package com.bawei.dome_gouwu3; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.CheckBox; import android.widget.ExpandableListView; import android.widget.TextView; import com.google.gson.Gson; import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; @BindView(R.id.main_checkbox) CheckBox mainCheckbox; private String url = "https://www.zhaoapi.cn/product/getCarts?uid=71"; private ExpandableListView expandableListView; private CheckBox checkBox; private TextView price; private TextView addbut; private MyAdapter myAdapter; private MyAddSubView myAddSubView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); expandableListView = findViewById(R.id.expandableListView); checkBox = findViewById(R.id.main_checkbox); price = findViewById(R.id.priceadd); addbut = findViewById(R.id.addbut); myAddSubView = findViewById(R.id.add_remove_view); Okhttutlis.getInstance().doGet(url, new Okhttutlis.OkCallback() { @Override public void onFailure(Exception e) { } @Override public void onResponse(String json) { Gson gson = new Gson(); Baen baen = gson.fromJson(json, Baen.class); String code = baen.getCode(); if (code.equals("0")) { List<Baen.DataBean> data = baen.getData(); myAdapter = new MyAdapter(data); myAdapter.setMonCartListChangeListener(new MyAdapter.onCartListChangeListener() { @Override public void onSellerCheckedChange(int groupPosition) { boolean currentSellerAllProductSelected = myAdapter.isCurrentSellerAllProductSelected(groupPosition); Log.d(TAG, " "+currentSellerAllProductSelected); myAdapter.changeCurrentSellerAllProductsStatus(groupPosition, !currentSellerAllProductSelected); myAdapter.notifyDataSetChanged(); refreshSelectedAndTotalPriceAndTotalNumber(); } @Override public void onProductCheckedChange(int groupPosition, int childPosition) { myAdapter.changeCurrentProductStatus(groupPosition, childPosition); myAdapter.notifyDataSetChanged(); refreshSelectedAndTotalPriceAndTotalNumber(); } @Override public void onProductNumberChange(int groupPosition, int childPosition, int number) { myAdapter.changeCurrentProductNumber(groupPosition, childPosition, number); myAdapter.notifyDataSetChanged(); refreshSelectedAndTotalPriceAndTotalNumber(); } }); expandableListView.setAdapter(myAdapter); for (int i = 0; i < data.size(); i++) { expandableListView.expandGroup(i); } } } }); } //刷新checkbox状态和总价和总数量 private void refreshSelectedAndTotalPriceAndTotalNumber() { Log.d(TAG,"价钱shuaxin"); boolean allProductsSelected = myAdapter.isAllProductsSelected(); checkBox.setChecked(allProductsSelected); float totalcost = myAdapter.Totalcost(); Log.d(TAG,""+totalcost); price.setText(totalcost + ""); int i = myAdapter.thetotalAmount(); addbut.setText("去结算(" + i + ")"); } @OnClick(R.id.main_checkbox) public void onViewClicked() { boolean allProductsSelected = myAdapter.isAllProductsSelected(); myAdapter.changeAllProductsStatus(!allProductsSelected); myAdapter.notifyDataSetChanged(); //刷新底部数据 refreshSelectedAndTotalPriceAndTotalNumber(); } }
购物的Activty
猜你喜欢
转载自blog.csdn.net/zzf0521/article/details/80864967
今日推荐
周排行