Especially if you want your list to scale to 1000 or more rows, you really want to avoid loading all of it up-front and instead rely on being able to construct a query the returns the results appropriately. Fwiw.
On Fri, Aug 28, 2009 at 12:05 PM, Mark Murphy <mmur...@commonsware.com>wrote: > > > 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 > > > > > > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---