I've hit a problem in changing over to a CursorAdapter. The custom
items in my ListView contained a Checkbox. After reading online, I had
successfully implemented maintaining the state of the Checkbox such
that it worked with view recycling: I was storing the state of the
Checkbox in the same object as was added to my ArrayAdapter. This way,
I was able to retrieve and set this state correctly in the getView()
method of my custom ArrayAdapter.

Now, when I switch over to a CursorAdapter, all of the data used to
populate my view is coming from a Cursor... I've figured out how to
handle view recycling over the new bindView() and newView() methods
(http://stackoverflow.com/questions/3535074/getview-vs-bindview-in-a-
custom-cursoradapter), but how do I handle this Checkbox state thing?
Does it now necessarily have to be a part of my database (seems to be
the case if all bindView() and newView() get is a Cursor...)? This
means that now every time a user checks/unchecks an item in my
ListView, I'm making a database update() call to save the Checkbox
state. Is this the way to do it?

Thanks for your patience. I'm trying to explain the problem as clearly
as I can, but to be honest, I'm just trying to understand it myself,
so I'm not sure if it is coming across in a coherent manner.

On Feb 24, 10:40 am, Kookamonga <[email protected]> wrote:
> Thanks for your answer.
>
> I'll change over to a CursorAdapter and see how things go.
>
> On Feb 24, 10:30 am, skink <[email protected]> wrote:
>
>
>
>
>
>
>
> > 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/threa....
>
> > > 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 [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

Reply via email to