tags:

views:

30

answers:

2

I'm implementing a custom adapter that iterates over some database entries which in turn link back to the Android contacts database. The adapter will make the query to the content resolver and bind the data from the returned cursor into the view. However, suppose I add a contact to my private database, then remove it from the Android contacts list. The query will fail, and ideally in that case I want to delete that entry from the database and try the next one, and invalidate the view that I'm supposed to be binding so it doesn't show up on the screen.

I don't see an obvious way to do that from the SDK docs, so I thought I'd ask lazyweb!

The other solution is to iterate through the whole private contact database on instantiation and prune all the bad entries, but I consider that very expensive.

+1  A: 

In this case you can't invalidate the view, you have to return a view set as invisible.

Use , this on the returned view

view.setVisibility(View.GONE);
Pentium10
+1  A: 

If the user switches to the contact list application your application will be paused. If you use a cursor adapter the adapter will deactivate the cursor and if you supplied true for auto requerry the cursor will be refreshed if you return to your app.

Is it possible to remove all the entries you don't want to show in the list in the sql statement you use to get the entries? Then this would make the cleanup nearly automatic.

Janusz
I appreciate the answer, but I think for performance concerns I'm going to go with Pentium10's solution for now. The reason that I can't just do this with auto requery is that the cursoradapter is for the database of contact IDs (inside the Android contact list.) Every time I bindView from that cursor adapter, it actually makes a followup query with that contact ID into the Android contact list. So I would need to preprocess the cursor on requery to check and remove all dead references, which is expensive.
Josh K