You don't have to create a new cursor. You can just change the sort value for the query, if all other things remain constant. That's why it's a parameter, so you alter it's value upon execution of the query.
best way to create sort order in the Cursor in android?
-
13-10-2022 - |
Question
Is creating different cursor for creating sort orders and distribute it in an model clases for alternating sorting style in an listview in android good practice?
titleCursor = context.getContentResolver().query(sourceUri, projection,
null, null, orderByTitle);
timeCursor = context.getContentResolver().query(sourceUri, projection,
null, null, orderByTime);
dateCursor = context.getContentResolver().query(sourceUri, projection,
null, null, orderByDate);
and values of its cursor will be destributed to each models to get the cursor for sorting for alternating sorting in listview? is it a good practice?
No correct solution
OTHER TIPS
Instead of creating a different cursor for each sort, you could maintain a string value or some integer value and based on the value inside an if condition simply change the sort parameter like:
if(value.equals("time")) {
cursor = context.getContentResolver().query(sourceUri, projection,
null, null, orderByTime);
}else if(value.equals("title")) {
cursor = context.getContentResolver().query(sourceUri, projection,
null, null, orderByTitle);
}
and so on.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow