So far in the sample application, the data items are displayed in their raw sort order, but we'd like to be able to sort and filter the data. Learn how to apply a sort order with an argument of the query() method. The sort order string is an SQL clause. If you want to sort by more than one column, pass in a comma-delimited list of column names. Or if you want sort in descending order, just pass in the DESC SQL keyword. Whatever string you pass in just becomes part of the SQL statement.
- [Teacher] So far in my sample application, I'm displaying…all of my data items in their raw sort order, but I'd like…to be able to explicitly sort and also to filter the data.…So I've added a few new features…to this version of the project.…First, I'll describe how to sort the data.…That's the easier part.…And I'll go to my DataSource class.…In the DataSource class, I'll locate…my getAllItems method down here, and I'll make…a very simple change to my query method call.…
The query method takes all of these different arguments,…and the very last argument is called orderBy.…This is a straight old SQL orderBy clause.…If you just want to sort in ascending order by a single…column, you just need to pass in the column name.…And that's what I'll do by passing in ItemsTable.COLUMN_NAME…meaning the name field of that class…matching the name column of the table.…And I'll run the code again,…and then I'll reload the application,…and I'll see the data comes out…in the appropriate sort order.…
And again, that sort order, as far as…
- Modeling data in POJO classes
- Customizing a ListView item display
- Displaying data in a RecyclerView
- Creating a custom array adapter
- Managing shared preferences with Java
- Creating and importing JSON data files
- Accessing SQLite from the command line
- Retrieving data with SQLite queries
Skill Level Intermediate
Android App Development: Data Persistence Librarieswith Annyce Davis3h 59m Intermediate
Android App Development: RESTful Web Serviceswith David Gassner2h 25m Intermediate
1. Display Static Data
2. Store Data in Shared Preferences
About shared preferences4m 41s
3. Store Data in Text Files
4. Manage Relational Data with SQLite
Next steps1m 43s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.