I have extended CursorAdapter and associated it with a ListView. I have two different layouts for the rows and have implemented getViewTypeCount
, getItemViewType
, newView
and bindView
. The data comes from an SQL table where each row has a layout column that indicates what kind of layout this item should have.
My getViewTypeCount
looks like this:
@Override
public int getItemViewType(int position) {
int layout = mCursor.getInt(mLayoutIndex);
if (layout == DataHelper.LIST_LAYOUT_ADD_PROJECT)
return 开发者_StackOverflow0;
else
return 1;
}
But this seems to screw up the recycling of views.
How can this be accomplished? Or is this a bad way of implementing this?
First of all, you shouldn't store the layout integer ID in persistent storage, these IDs can (and will) change with later compilations based on the order and names of things, so it will most likely come bite you later. This might actually be the source of your troubles.
The other thing that I see is that you don't use the position
argument that was provided to you, so how do you know that the data in mCursor
corresponds to the current position being queried?
精彩评论