What's Your Preference?Figure 30. The available sort ordersOf course, none of this is actually having any effect on the sort order itself,
which we will address in the next section.
Step #4: Apply the Sort Order on Startup.........................................
Now, given that the user has chosen a sort order, we need to actually use it.
First, we can apply it when the application starts up – the next section will
handle changing the sort order after the user changes the preference value.
First, the getAll() method on RestaurantHelper needs to take a sort order as
a parameter, rather than apply one of its own. So, change that method as
follows:
public Cursor getAll(String orderBy) {
return(getReadableDatabase()
.rawQuery("SELECT _id, name, address, type, notes FROM restaurants
ORDER BY "+orderBy,
null));
}