views:

143

answers:

1

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<?>?

+1  A: 

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.

CommonsWare