Implementing a content provider for an existing database is very easy.
You can probably do it within an hour is you know what you are doing.

On Apr 6, 7:33 am, vl <[EMAIL PROTECTED]> wrote:
> From the description of ContentProvider class "A content provider is
> only required if you need to share data between multiple applications.
> For example, the contacts data is used by multiple applications and
> must be stored in a content provider. If you don't need to share data
> amongst multiple applications you can use a database directly via
> SQLiteDatabase."
>
> I decided to use database directly, because there is no need to share
> data with other applications. Also it looked like a simpler approach
> for complex queries with complex constraints and joins.
>
> There are few moments that I cannot figure out.
> 1. How properly notify about deleted item.
> 2. How properly notify about inserted item.
>
> ListActivity creates cursor which is managed by that activity. There
> is also corresponding list adapter.
>
> public class MyActivity extends ListActivity {
>
>     public void onCreate(Bundle icicle) {
>         mCursor = ...;
>         this.startManagingCursor(mCursor);
>
>         ResourceCursorAdapter adapter = new
> ResourceCursorAdapter(this, R.layout.mylayout, mCursor) {
>                 public void     bindView(View view, Context context, Cursor
> cursor) {
>                          ...
>                 }
>         }
>        setListAdapter(adapter);
>
>     }
>
> When another activity is invoked to edit the selected item -
> everything is fine. The same item remains selected (even if it changes
> position in the list due to the modification of its attributes that
> are used for sorting) and it shows the recent values in the list.
>
> The following method of the same list adapter is executed to delete an
> item
>
>     private void deleteSelectedItem() {
>        SQLiteDatabase db = ...
>        db.delete("MyTable", "_id = ?", new String[]
> {String.valueOf(getSelectedItemId())});
>
>        // FIXME: How to notify the ListAdapter about the change?
>     }
>
> I tried to execute mCursor.requery() as a mean of notification. It
> forces the list to be updated, but all items are shown as not
> highlighted. I can see the following sequence of actions in UI - list
> is redrawn without deleted item, the next item is shown highlighted,
> then next item is shown as not highlighted. When up or down key is
> clicked - item is highlighted again, so for the list adapter the
> deleted item is still a selected item.
>
> The problem with inserted item is similar, but slightly more complex.
> The item is created in another activity (do not want to make it sub-
> activity, because there is nothing to return, if notification works).
> The next item must be shown highlighted, so somehow list must be
> notified about new item id and new selection. The position of a new
> item in the list depends on attribute values, created for that item,
> so the list view must be scrolled automatically to make a new item
> visible when list activity becomes active again.
>
> I am afraid it's too late for me to switch to content provider
> implementation to make it work.
>
> Any help?
--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to