> Here is what I do in more detail: > - Query encrypted data from SQL, this gives me a Cursor > - Create SimpleCursorAdapter with that cursor and give it to ListView > - I have my own ViewBinder that decrypts data as the ListView is > populated. > > I'm not sure if I want to reap data from the cursor, pass it over to > the collection, sort it and give it to the ListView for performance > reasons. So I was kind of hoping that it would be possible to sort the > list view items when they are already in the list.
Once "they are already in the list", sorting them will be massively slower. Orders of magnitude slower. A glacier might move faster. For a list of N rows: -- You would be forcing Android to inflate N rows, rather than only the rows presently visible, costing CPU time to create them and lotsa RAM to hold them -- You will need to get the strings back out of their TextViews (or whatever you are putting them in) for sorting purposes -- For N bigger than a couple dozen, you may blow out your available stack space due to processing all of the row Views as actual Views, crashing your application and making the whole issue of sorting rather moot -- You would have to do the sort on the UI thread, which means you will likely get an ANR dialog and have your activity force-closed, if N is anything large, due to the time all of this takes Better options for how to do that sort include: 1. Skip the encryption outright, and use an ORDER BY clause in the database query 2. Choose an encryption algorithm that will maintain proper collation (not sure if this is practical), and use an ORDER BY clause in the database query 3. Store, in an unencrypted column, a column that contains a sequence number for sorting purposes (think line renumbering schemes from 1980's TRS-80 Basic), and use an ORDER BY clause on that column in the database query 4. Pour the Cursor contents into an ArrayList and sort that, as Roman suggested #4 is probably the simplest, though perhaps not the quickest. All of those can be done in a background thread, such as an AsyncTask, to keep the UI from freezing. -- Mark Murphy (a Commons Guy) http://commonsware.com Android App Developer Books: http://commonsware.com/books.html --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

