[android-developers] Re: Maintaining sorted state of a ListView
Kookamonga wrote:
> I have what seems like a very basic question: how can I maintain the
> sorted state of a ListView as new items are added to the list?
>
> I have a ListView that is populated from a database. Specifically, I
> query my database, create an ArrayList of items, and use a custom
> ArrayAdapter<MyType> as the adapter of the ListView.
>
> Now, I understand that I can use ORDER BY in my db query when
> initially populating the list. But what about when new items are
> inserted? I also understand that I can call the .sort() method on the
> ArrayAdapter<...> passing in a Comparator... But does this mean that I
> have to call sort every time a new object is added to my database (and
> thus, my ListView is updated)? That doesn't seem right.
>
> The answer here (http://stackoverflow.com/questions/3496137/how-to-
> update-a-cursoradapter-tied-to-listview-when-number-of-items-changes)
> by JRL seems to indicate that using a CursorAdapter doesn't really
> solve the problem either.
>
> I have searched around but not found an answer to this question. All
> I've found is help on how to sort in the first place, for example:
> http://groups.google.com/group/android-developers/browse_thread/thread/b21831ed773bf1fa.
>
> What I need is something like a setSorter(...) method that's available
> on certain Eclipse Viewers. Does something like this exist?
>
> Thanks as usual for your help!
what you need is a CursorAdapter, nothing more
pskink
--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home