jeudi 15 septembre 2016

How to get ID and Value of multiple checkbox groups in android?

I have multiple checkbox group and i want to store the value of checked checkbox(s) and ID in some array list (Provided it should be unique)

example:-

screenshot with multiple checkbox group how to set unique value to each checkbox group and so to checkboxes

these are my arraylist of checkbox type

List<CheckBox> checkBoxList = new ArrayList<>();
try {
                    dataArrayListcheckbox = new ArrayList<String>();

                    for (int j = 0; j < tagValueBeanList.size(); j++) {

                        checkBox = new CheckBox(this);
                        checkBox.setText(tagValueBeanList.get(j).getTag().toString());
                        checkBox.setLayoutParams(spinnerParams);
                        checkBox.setId(Integer.parseInt(tagValueBeanList.get(j).getValue().toString()));
                        checkBox.setTextSize(25);
                        checkBox.setId(participantCount);
                        linearLayout.addView(checkBox);
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            checkBox.setButtonTintList(ColorClass.colorStateList());
                        }
                        final int finalJ = j;
                        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                            @Override
                            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                                if (isChecked) {

                                    dataTag = buttonView.getText().toString().trim() + " | " + buttonView.getId();
                                    dataArrayListcheckbox.add(dataTag);
                                    System.out.println("ID Selected: " + buttonView.getId());
                                    System.out.println("Text Selected: " + buttonView.getText().toString());
                                    checkBoxHashMap.put(buttonView.getId(), buttonView.getText().toString());
                                }
                                if (!isChecked) {
                                    try {

                                        checkBoxHashMap.remove(buttonView.getId());
                                        for (int i = 0; dataArrayListcheckbox.size() > i; i++) {
                                            System.out.println(buttonView.getText().toString() + ">>>>UUUUcheck" + dataArrayListcheckbox.get(i).toString());
                                            String tageValue = buttonView.getText().toString().trim();
                                            String tagID=String.valueOf(buttonView.getId()).trim();
                                            String arrayTagValue = dataArrayListcheckbox.get(i).toString();

                                            System.out.println(">>>true comatin>");

                                            String res12[] = arrayTagValue.split("\\|");
                                            String tag = "", value = "";
                                            for (int tagCount = 0; res12.length > tagCount; tagCount++) {
                                                if (tagCount == 0) {
                                                    tag = res12[0].toString().trim();
                                                } else {
                                                    value = res12[1].toString().trim();
                                                }
                                            }

                                            if (tageValue.equalsIgnoreCase(tag) && tagID.equalsIgnoreCase(value) ) {
                                                System.out.println(">>>true comatin>" + dataArrayListcheckbox.size());
                                                System.out.println(tageValue + "conatain...." + tag);
                                                dataArrayListcheckbox.remove(i);
                                                System.out.println(">>>true comatin>" + dataArrayListcheckbox.size());

                                            }

                                            for (int count = 0; count < dataArrayListcheckbox.size(); count++) {
                                                System.out.println("" + dataArrayListcheckbox.get(count));
                                            }
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }

                            }
                        });
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }    

how to get values of each checkbox group with its ID Thanks

PS:- Sorry for my bad english




Aucun commentaire:

Enregistrer un commentaire