-1

I am using a checked ListView in a dialog. I am able to get all the checked items ans store it like this:

builder.setMultiChoiceItems(arr, null,
        new DialogInterface.OnMultiChoiceClickListener() {
            // indexSelected contains the index of item (of which checkbox checked)
            @Override
            public void onClick(DialogInterface dialog, int indexSelected,
                                boolean isChecked) {
                if (isChecked) {
                    brandNameIDMap.put(brandList.getItem(indexSelected).getProductID(), brandList.getItem(indexSelected).getProductName());
                    //Log.i("ID", "onClick: "+brandList.getItem(indexSelected).getProductID());
                    //seletedItems.add(indexSelected);
                } else{
                    brandNameIDMap.remove(brandList.getItem(indexSelected).getProductID());
                }
            }
        });

PROBLEM: Now I want to reopen the Dialog and the items that were selected previously needs to be selected automatically. How can I do this?

Aastha Doshi
  • 147
  • 1
  • 14
3iL
  • 2,146
  • 2
  • 23
  • 47

1 Answers1

0

Create an array

Boolean checked[] = new Boolean[arr.size()];

Then onchecking any item add that to the array like this.

 builder.setMultiChoiceItems(arr, checked,
            new DialogInterface.OnMultiChoiceClickListener() {
                // indexSelected contains the index of item (of which checkbox checked)
                @Override
                public void onClick(DialogInterface dialog, int indexSelected,
                                    boolean isChecked) {

                    if (isChecked) {
                        checked[indexSelected]=true;
                        brandNameIDMap.put(brandList.getItem(indexSelected).getProductID(), brandList.getItem(indexSelected).getProductName());
                        //Log.i("ID", "onClick: "+brandList.getItem(indexSelected).getProductID());
                        //seletedItems.add(indexSelected);
                    } else{
                        checked[indexSelected]=false;
                        brandNameIDMap.remove(brandList.getItem(indexSelected).getProductID());
                    }
                }
            });
Sharath kumar
  • 4,064
  • 1
  • 14
  • 20