Wrong size of array when checking in a function

118 views Asked by At

I'm trying to get all checked items from a list view in a Sparse boolean array and passing that array to a function which shows the user a dialog and on clicking yes does some stuff in the db for the selected items in the Sparse array.

The problem I'm facing is before calling the function I check the size of Sparse array and it shows the correct size but the function I pass it to, as soon as it gets called it shows a size of 0. I have no clue as to why that is happening.

Here is what I'm doing --->

SparseBooleanArray checkedPositions;
switch (item.getId()) {
    case delete : 
        checkedPositions = listView.getCheckedItemPositions();
        Log.d(TAG, checkedPositions.size());
        confirmDeletion(checkedPositions);
        break;
}

And this is the method I'm passing it to --->

confirmDeletion(final SparseBooleanArray checkedPositions) {
    Log.d(TAG, checkedPositions.size());
}

For the first log I get correct size but 0 in the second log. I can't figure out what's going wrong. Any help would be much appreciated.

1

There are 1 answers

0
Alex On

Since there is no SSCCE I can guess that your flow is not what you think. Add stack trace to the logging so you can see who and when calls confirmDeletion() method.

Another suggestion would be assurance that you use the same object. Add toString for the logging to see sequence of the flow and that the same object is used. After all the same object does return the same result so it definitely looks like there is some gap and you are using different objects.