1

My items in my list view activity are not cleared, i.e. they remain checked internally.

    @Override
            public boolean onActionItemClicked(ActionMode mode,
                    MenuItem item) {

                if(item.getTitle() == "Add")
                {
                    Intent returnIntent = new Intent();
                    ArrayList<String> path = new ArrayList<String>();
                    SparseBooleanArray checked = listView.getCheckedItemPositions();
                    for(int i=0; i<checked.size(); i++)
                    {
                        if(checked.valueAt(i)){
                            MusicItem mItem = (MusicItem) listView.getItemAtPosition(i);
                            path.add(mItem.getAbsolutePath());
                        }
                    }
                    returnIntent.putStringArrayListExtra("path", path);
                    setResult(RESULT_OK, returnIntent);
                                            mode.finish();
                    finish();
                    return true;
                }

                return false;
            }

I guess this is the part where I'm doing something wrong here!!

    @Override
            public void onDestroyActionMode(ActionMode mode) {
                listView.clearChoices();
                for(int i=0; i<listView.getChildCount(); i++){
                    listView.setItemChecked(i, false);
                }
            }

The for loop in 'onDestroyActionMode' gives "StackOverFlowError". And 'clearChoices()' doesn't work for some reason. Any help would be appreciated!! Thank you!

Abdul Qadir
  • 129
  • 10

1 Answers1

0

The following loop gave me "StackOverFlowError" when I put it in "onDestroyActionMode"

    for(int i=0; i<listView.getCount(); i++)
    {
        listView.setItemChecked(i, false);
    }

But when I put this on 'onCreate' of my list view activity. It worked fine. No idea why though. This is the only solution I could find as none of the solutions posted here worked for me: ListView selection remains persistent after exiting choice mode

Community
  • 1
  • 1
Abdul Qadir
  • 129
  • 10