I have another problem. I was scheduling an alarm for each item in my ListView. Users were able to edit the time for the alarm by editing the item in the ListView. Per the docs, I had to cancel the previously set alarm myself and set a new alarm for the updated time as specified by the user during their edit (i.e. there was no way to replace a previously set alarm...).
In the previous way of doing things, with a custom ArrayAdapter<>, I was of course using a custom object type as the contents of the ListView. I had added a field of type PendingIntent to this object. This way, when a user clicked on an item in the ListView, I could retrieve the custom object backing this item and then cancel the PendingIntent that had previously been scheduled. But now, if I use a CursorAdapter, the "object backing this item" is simply a Cursor. How would I maintain such an association between some custom object and an item in my ListView? It seems as though using a CursorAdapter severely limits our freedom in terms of saving content to be associated with an item in the ListView WITHOUT adding it to the database itself. Thanks again for your help and patience. It certainly isn't easy navigating through all of this for the first time. On Feb 24, 12:54 pm, Kookamonga <site...@yahoo.ca> wrote: > Looks like once again, it was all about Googling for the right > thing:https://www.google.com/search?q=listview+cursoradapter+checkbox > > My bad. > > On Feb 24, 11:37 am, Kookamonga <site...@yahoo.ca> wrote: > > > > > > > > > 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 <site...@yahoo.ca> wrote: > > > > Thanks for your answer. > > > > I'll change over to a CursorAdapter and see how things go. > > > > On Feb 24, 10:30 am, skink <psk...@gmail.com> 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 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