Skip to content Skip to sidebar Skip to footer

How To Make Selected Checkbox Item?

I am getting response from server,and I use textview,and on textview's click listener I set alertdialog,where user can select multiple items,but when values from server via reponse

Solution 1:

Lets say you got 'unmarried' in your json object.

So, this is what you will do -

CharSequence[] _options = { "UnMarried", "Widow/Widower", "Divorcee",
                "Separated" };
        String[] valueFromJson = { "UnMarried", "Divorcee" }; // you will pass// your// value from// JSON// to this// variableboolean[] isSelected = newboolean[_options.length];
        boolean[] _selections = newboolean[_options.length];

publicboolean[] markChecked() {

        int[] locations = newint[valueFromJson.length];
        for (int i = 0; i < valueFromJson.length; i++) {
            int index = Arrays.asList(_options).indexOf(valueFromJson[i]);
            locations[i] = index;
            System.out.println(index + " " + valueFromJson[i]);

        }
        int k = 0;
        for (int i = 0; i < isSelected.length; i++) {
            if (k< locations.length && locations[k] == i) {
                isSelected[i] = true;
                k++;
            } else {
                isSelected[i] = false;
            }
            System.out.println(isSelected[i]);
        }
        return isSelected;

    }

now do this -

.setMultiChoiceItems(_options, markChecked(), new DialogSelectionClickHandler())

Post a Comment for "How To Make Selected Checkbox Item?"