I am trying to achieve what should be a very simple task.  Create a
ListView that allows multiple selection, set some initial values
selected, display the ListView and then retrieve the selected items
once the user has finished manipulating the list.

I have a custom dialog with a ListView and the following in the
constructor

        ListView theList = (ListView)
findViewById(R.id.excluded_apps_list);
        theList.setItemsCanFocus(false);
        theList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

        ArrayAdapter<String> arrayAdapter = new
ArrayAdapter<String>(context, R.layout.appspicker_itemview, test);
        theList.setAdapter(arrayAdapter);

        for (String s : _itemNames) {
                arrayAdapter.add(s);
        }

        theList.setItemChecked(0, true);

The list displays fine and the first item is checked as expected.
Once the dialog closes I do the following to get the checked item
positions:

        ListView theList = (ListView)
findViewById(R.id.excluded_apps_list);
        SparseBooleanArray checked = theList.getCheckedItemPositions();

The problem is that even if I deselect the first item and then close
the dialog, getCheckedItemPositions() still indicates that the item is
checked.  If I remove the call to setItemChecked(), everything works
fine but I really need the ability to set the inital checked state of
the list items.

Any ideas what I'm doing wrong?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to