ListAdapters and WrapperListAdapter algorithm
This logic is written in a function with signature
private void showDialog(final AdapterView<? extends Adapter> parent,
String title, String message, final Tag subject)
Is there a better way of doing this?
// refresh adapter
SimpleCursorAdapter adapter;
if (parent.getAdapter() instanceof WrapperListAdapter) {
adapter = (SimpleCursorAdapter) ((WrapperListAdapter) parent.getAdapter()).getWrappedAdapter();
} else {
adapter = (SimpleCursorAdapter) parent.getAdapter();
}
adapter.getCursor().requery();
adapter.notifyDataSetChanged();
Also, is there any point in having AdapterView<? extends Adapter>
in the signatu开发者_Go百科re and not just AdapterView<?>
?
Is there a better way of doing this?
Hold onto your Cursor
object and call requery()
on it, rather than trying to dig it out from your adapter.
Also, ideally, you would not need to call notifyDataSetChanged()
-- CursorAdapter
does this automatically, and hopefully the WrapperListAdapter
will hook into the CursorAdapter
and cascade the notifyDataSetChanged()
operation.
Also, is there any point in having AdapterView in the signature and not just AdapterView?
That syntax will throw a compiler error if you attempt to create an AdapterView
on an Integer
, or a Button
, or a Socket
. In other words, it adds a bit of compile-time type safety.
精彩评论