When implementing bindView() for an adapter, can I 'skip' a view?
I'm implementing a custom adapter that iterates over some database entries which in turn link b开发者_开发百科ack 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.
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);
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.
精彩评论