How Does The Sortcursor From The Aosp Repository Sort It's Values
Solution 1:
There are two important things to know about the SortCursor.
1. It reads values from the cursors as strings and not numbers so the string "70" is smaller than the string "8".
2. It only compares the next value of each cursor when it is looking for the smallest value. So each individual cursor have to be sorted before it's given to the SortCursor.
So with the given example "70" is smaller than "9" so that goes first, then "8" is smaller than "9" so that goes next, "6" is smaller than "9" so that goes next. Then only the values in the first cursor remains.
As you see the cursor you used is actually sorted, its just not sorted in the way you expect it to be sorted.
If you sort your individual cursors before you create the SortCursor and use strings instead of numbers you will get the expected result.
MatrixCursor matrixCursor1 = newMatrixCursor(columnNames);
matrixCursor1.addRow(newString[]{"cursor 1 value C", "01"});
matrixCursor1.addRow(newString[]{"cursor 1 value B", "02"});
matrixCursor1.addRow(newString[]{"cursor 1 value A", "09"});
MatrixCursor matrixCursor2 = newMatrixCursor(columnNames);
matrixCursor2.addRow(newString[]{"cursor 2 value C", "06"});
matrixCursor2.addRow(newString[]{"cursor 2 value B", "08"});
matrixCursor2.addRow(newString[]{"cursor 2 value A", "70"});
Will give you
V/SortCursor: Name: cursor 1 value C, Value: 01
V/SortCursor: Name: cursor 1 value B, Value: 02
V/SortCursor: Name: cursor 2 value C, Value: 06
V/SortCursor: Name: cursor 2 value B, Value: 08
V/SortCursor: Name: cursor 1 value A, Value: 09
V/SortCursor: Name: cursor 2 value A, Value: 70
Post a Comment for "How Does The Sortcursor From The Aosp Repository Sort It's Values"