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 signature and not just AdapterView<?>?
Hold onto your
Cursorobject and callrequery()on it, rather than trying to dig it out from your adapter.Also, ideally, you would not need to call
notifyDataSetChanged()—CursorAdapterdoes this automatically, and hopefully theWrapperListAdapterwill hook into theCursorAdapterand cascade thenotifyDataSetChanged()operation.That syntax will throw a compiler error if you attempt to create an
AdapterViewon anInteger, or aButton, or aSocket. In other words, it adds a bit of compile-time type safety.