I know there must be an { Observable->Observer, Observable->Observer, … } chain from ContentProvider to ListView (or general AdapterView), but I didn’t know how exactly this chain is composed.
I put by the itch to untangle the knot until recently I set out to implement an OrderedMergeCursor1, which should be a subclass of MergeCursor that merge-sorts pre-ordered cursors.
It turns out that the chain is quite long, and kinda entangled by the two content data concepts of Cursor: Content(ContentObservable->ContentObserver) and DataSet(DataSetObservable->DataSetObserver).
As I see it, Cursor’s Content is the source Cursor retrieves data from, while Cursor’s DataSet is the data Cursor has retrieved. It will be more clear in the notification chain below.
For simplicity, I will omit the enclosed ContentObservable/DataSetObservable of Cursor and Adapter, since they are just one more indirect layer without any real functionalities. You can think of Cursor and Adapter as Observable themselves.
Without further ado, here comes the untangled register chain and the opposite notification chain.
ListView.setAdapter(CursorAdapter): Adapter.registerDataSetObserver(AdapterView.AdapterDataSetObserver) ^ ^ CursorAdapter <- CursorAdapter(Context, Cursor): Cursor.registerContentObserver(CursorAdapter.ChangeObserver) Cursor.registerDataSetObserver(CursorAdapter.MyDataSetObserver) ^ ^ Cursor <- ContentResolver.query(Uri, String[], String, String[], String): ContentProvider.query(Uri, String[], String, String[], String): AbstractCursor.setNotificationUri(ContentResolver, Uri): ContentResolver.registerContentObserver(Uri, boolean, AbstractCursor.SelfContentObserver) |
ContentResolver.notifyChange(Uri, ContentObserver) ---> AbstractCursor.SelfContentObserver.onChange(boolean) ---> AbstractCursor.onChange(boolean) ---> CursorAdapter.ChangeObserver.onChange(boolean) ---> AbstractCursor.requery() ---> CursorAdapter.MyDataSetObserver.onChanged() ---> BaseAdapter.notifyDataSetChanged() ---> AdapterView.AdapterDataSetObserver.onChanged() ---> View.requestLayout() |
© Wangling. Powered by WordPress using the DePo Skinny Theme.