1

I create AlertDialog with ListView, and adapter have element CheckAll/UncheckAll elements programmatically. This works. But when I'm checking item by touching screen, then push checkall, then uncheckall the checked element stays checked.

    DialogInterface.OnMultiChoiceClickListener coloursDialogListener = new DialogInterface.OnMultiChoiceClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which,
                boolean isChecked) {

            ListView list = ((AlertDialog) dialog).getListView();
            long[] a = list.getCheckItemIds();
            if (which == 0) {
                if (isChecked) {
                    for (int i = 0; i < list.getCount(); ++i)
                        list.setItemChecked(i, true);
                } else {
                    for(int i=0;i<list.getCount();++i)
                        list.setItemChecked(i, false);
                }
                a = list.getCheckItemIds();//fucntion return empty array
                                    //but on screen checked element is Check.
                return;
            }
        }
    };

Update: I'm find when the bug occurs. if in function

setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener listener)

I set parameter checkedItems the bug occurs. And if I set checkedItems parameter null bug not occurs. Have any idea?

UPDATE: I open the issue on bugtracker google, for more datails look here

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
silentnuke
  • 2,622
  • 1
  • 18
  • 17

1 Answers1

1

getCheckItemIds() This method is deprecated. Use getCheckedItemIds() instead.

http://developer.android.com/reference/android/widget/ListView.html

MikeIsrael
  • 2,871
  • 2
  • 22
  • 34
  • i'm use api level 7. getCheckItemIds() requries api level 8. i changed api level to 8, but getCheckedItemIds always return empty array , even if the items are checked. and main error remained – silentnuke Dec 28 '11 at 21:25