点击按钮删除购物车数据(弹框AlertDialog)

  btnRome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean flag = false;
                for (int i = 0; i < lists.size(); i++) {
                    for (int j = 0; j < lists.get(i).size(); j++) {
                        boolean childCb = lists.get(i).get(j).isChildCb();
                        if (childCb == true) {
                            flag = true;
                        }
                    }
                }
                if (flag) new AlertDialog.Builder(getActivity())
                        .setTitle("提示")
                        .setMessage("确认要删除吗?")
                        .setPositiveButton("是", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                for (int s = 0; s < lists.size(); s++) {
                                    for (int j = 0; j < lists.get(s).size(); j++) {
                                        boolean childCb = lists.get(s).get(j).isChildCb();
                                        if (childCb) {
                                            Map map = new HashMap<>();
                                            SharedPreferences user = getActivity().getSharedPreferences("User", Activity.MODE_PRIVATE);
                                            String userID = user.getString("UserID", null);
                                            map.put("uid", userID);
                                            map.put("pid", lists.get(s).get(j).getPid() + "");
                                            HttpUtils.getInstance().get("http://120.27.23.105/product/deleteCart", map, new CallBack() {
                                                @Override
                                                public void onSuccess(Object o) {
                                                    DeleteBean da = (DeleteBean) o;
                                                    String msg = da.getMsg();
                                                    Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
                                                }

                                                @Override
                                                public void onFailed(Exception e) {
                                                }
                                            }, DeleteBean.class);
                                        }
                                    }
                                }
                                allCheckbox.setChecked(false);
                                all2Checkbox.setChecked(false);
                                LinearLayoutTop.setVisibility(View.VISIBLE);
                                LinearLayoutButton.setVisibility(View.GONE);
                                list.clear();
                                lists.clear();
                                presenter.get();
                                expandableAdapter.notifyDataSetChanged();
                                changesum(lists);
                            }
                        }).setNegativeButton("否", null)
                        .create().show();
                else {
                    Toast.makeText(getActivity(), "未选中数据", Toast.LENGTH_SHORT).show();
                }
            }
        });

你可能感兴趣的:(点击按钮删除购物车数据(弹框AlertDialog))