Reputation: 36001
Before I start a full blown DB table project that is shown in a list, I'd like to understand better on what happens to the UI when the DB data is changed.
Imagine showing a list of 1000 items using a cursor adapter. Now some rows are added/deleted to/from the list. Now a new cursor needs to be loaded into the the Cursor adapter (using changeCursor).
What happens to the list (ListView) shown to the user? Does the user sees this reload? Does the list stays in the same place?
Upvotes: 2
Views: 862
Reputation: 44118
After a quick test, looks like the adapter uses positions to navigate.
After the cursor is swapped the adapter stays at the previous position.
If the new cursor has less available items (thus less positions), the last visible item will be the last item in the cursor.
Basically the list won't move visually as long as items up until the last visible item don't change.
As for the technical stuff:
First of all changeCursor
acts the same as swapCursor
the only difference being that changeCursor
also closes the previous cursor.
Once swapCursor
is called and the new cursor is not null, notifyDataSetChanged
gets called.
If you had enough convertViews
(re-usable views) created before the swap, bindView
is called on the visible views, to change the text / images or w/e you bind to your views. That change is obviously visible to the user.
If however you didn't have enough views then newView
is called and views are created before calling bindView
as above. Again this will be visible to the user because new items are added to the list.
Upvotes: 4