I'm using addFooterView to add a footer view to a ListView, which is
populated by a CursorAdapter controlled by Loader. Sometimes the
ListView tries to recycle the footer view however (through
CursorAdapter.bindView). This causes either ClassCastException (if
I allow the recycle) or some item views shown as footer view (if I do
not allow the recycle).
If I understand it right, the footer views added by addFooterView are
not supposed to be recycled ("Footer views are special views at the
bottom of the list that should not be recycled during a layout").
So this is probably a bug in Android APIs.
Is there any way to work around this problem? What is the correct way
to add footer views to a ListView populated by CursorAdapter?
Some relevant code:
In the activity:
paletteView = (ListView)findViewById(R.id.palette);
paletteView.addFooterView(new PaletteAdapter.NewSlot(this));
paletteAdapter = new PaletteAdapter(this, null);
paletteView.setAdapter(paletteAdapter);
getLoaderManager().initLoader(0, null, this);
In the adapter (PaletteAdapter):
@Override public void
bindView(View view, Context context, Cursor cursor)
{
if (view instanceof NewSlot)
{
Log.wtf(TAG,
("Recycle NewSlot to ID "
+ cursor.getLong(cursor.getColumnIndex
(DataProvider.Palettes._ID))));
return;
}
final Slot slot = (Slot)view;
// Blah blah...
}