views:

948

answers:

1

An OnItemClickListener for a ListView has the following method:

@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id)

I'd like to have the adapter behind the ListView refresh, and I believe this is done through the use of:

BaseAdapter.notifyDataSetChanged()

How do I use the parent parameter in the onItemClick method to do this? So far I've tried:

parent.getAdapter().notifyDataSetChanged();

This throws an error because the object returned is of class HeaderViewListAdapter, which for reasons unknown isn't a subclass of BaseAdapter.

A: 

AFAIK, there isn't any method in HeaderListView for data refresh/reload. The only way I can think of doing this is to reassign the adapter.

Karan
But there is the notifyDataSetChanged method in the BaseAdapter class. The adapter I've added to the ListView is a SimpleCursorAdapter which is a subclass of BaseAdapter - so I should be able to somehow get the SimpleCursorAdapter in the ListView onItemClick method, right?
Matty F
If its a instance of SimpleCursorAdapter then typecast it to base adapter and call notifyDataSetInvalidated().
Karan
The problem is that the onItemClick event passes in an AdapterView (parent), and performing getAdapter() returns a HeaderViewListAdapter.When I use getWrappedAdapter() this returns a ListAdapter and unfortunately BaseAdapter is a subclass of this, so I can't yet use the notify methods even though in this instance the underlying adapter of the ListView is a SimpleCursorAdapter. How can I get a reference back to the ListView's implemented adapter?
Matty F
You're right, I needed to typecast the ListAdapter:HeaderViewListAdapter adapterwrap = (HeaderViewListAdapter) parent.getAdapter();BaseAdapter adapter = (BaseAdapter) adapterwrap.getWrappedAdapter();
Matty F