Cursor Binding vs Object list Binding in android
I need some help with listview binding. I have read that the most effective way to use a listview binded to a datasource is to use a cursor which speaks directly to sqlite. I start my project using this method but I'm not able to face a critical for my application issue.
I need to change values of the binded list but those chang开发者_Go百科es doesn't affect my database until user press save button. In c# I can do this in many ways like datatable or bindingsource objects.
For example, my app has a list with products with their prices. I want to change prices through a popup window which open from context menu. When the popup window close I need to display the new price in listview but I haven't save it into database yet. Finally when I have change prices of all products I want to press save button and update my database using a transaction.
Is there any way to succeed something like this using cursors for binding or I have to use lists of custom class objects?
Seems like using custom data objects would be a good way doing it:
- read your products from database into a
list
of customProduct
objects, then useArrayAdapter
to display the data in theListView
- after changing price on a product call
notifyDataSetChanged
on the adapter to redraw the list with new values - when save button pressed - use the list of the
Products
to generate database updates in a single transaction
精彩评论