public class GWCFragment extends Fragment implements GWDataFac{ private View view; private MyExpanableListView myExpanableListView; private GWPersent gwPersent; private CheckBox checkBox; private TextView gwc_zongjia; private TextView gwc_allsum; private CountPriceBean countPriceBean; private Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what==0){ countPriceBean = (CountPriceBean) msg.obj; //设置价格和数量 gwc_zongjia.setText("合计:¥"+ countPriceBean.getPriceString()); gwc_allsum.setText("去结算("+ countPriceBean.getCount()+")"); } } }; private RelativeLayout relative_progress; private GwAdapter gwAdapter; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = View.inflate(getActivity(), R.layout.gwc_layout, null); //查找控件 initView(); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); gwPersent = new GWPersent(this); checkBox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { gwAdapter.setAllChildsChecked(checkBox.isChecked()); } }); } @Override public void onResume() { super.onResume(); //显示进度条 relative_progress.setVisibility(View.VISIBLE); gwPersent.setUrl(ApiUtil.cartUrl); } //查找控件 private void initView() { myExpanableListView = (MyExpanableListView) view.findViewById(R.id.gw_myExpanableListView); myExpanableListView.setGroupIndicator(null); checkBox = (CheckBox) view.findViewById(R.id.gwc_quanxuan_checkbox); gwc_zongjia = (TextView) view.findViewById(R.id.gwc_zj); gwc_allsum = (TextView) view.findViewById(R.id.gwc_zs); relative_progress = (RelativeLayout) view.findViewById(R.id.relative_progress); } @Override public void onSuccess(final GWBean gwBean) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { //获取数据成功...隐藏 relative_progress.setVisibility(View.GONE); //点击结算 创建订单 gwc_allsum.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (countPriceBean.getCount()>0){ Map<String,String> map=new HashMap<String, String>(); map.put("uid","3410"); map.put("price",countPriceBean.getPriceString()); OkHttp3Util.doPost(ApiUtil.createOrderUrl, map, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { } }); Intent intent=new Intent(getActivity(), DDActivity.class); startActivity(intent); }else { Toast.makeText(getActivity(), "购物车为空", Toast.LENGTH_SHORT).show(); } } }); if (gwBean!=null){ for (int i=0;i<gwBean.getData().size();i++){ List<GWBean.DataBean.ListBean> list = gwBean.getData().get(i).getList(); gwBean.getData().get(i).setGroupChecked(isChildInGroupChecked(list)); } //2.根据所有商家选中的状态,改变全选的状态 checkBox.setChecked(isAllGroupChecked(gwBean)); //设置适配器 final List<GWBean.DataBean> data = gwBean.getData(); gwAdapter = new GwAdapter(data,getActivity(),handler,gwPersent,relative_progress); myExpanableListView.setAdapter(gwAdapter); //展开所有的组...expanableListView.expandGroup() for (int i = 0;i<data.size();i++){ myExpanableListView.expandGroup(i); } //3.计算总价和商品的数量 gwAdapter.sendPriceAndCount(); } } }); } private boolean isAllGroupChecked(GWBean gwBean) { for (int i=0;i<gwBean.getData().size();i++){ if (!gwBean.getData().get(i).isGroupChecked()){ return false; } } return true; } private boolean isChildInGroupChecked(List<GWBean.DataBean.ListBean> list) { for (int j=0;j<list.size();j++){ if (list.get(j).getSelected()==0){ return false; } } return true; } }
GWWWWWWWWE
最新推荐文章于 2023-03-15 10:35:19 发布