So here's the story:
I want to use two layouts in my adapter. So basically, I need to have an if in the newView() to determine which view to return and and an if in bindView() to know as well what to do in the view. Is this the right approach?
I'm thinking of something like this:
@Override
public View newView(Context context, Cursor c,
ViewGroup parent) {
if (HEADER == getItemViewType(c.getPosition())){
return (View) layoutInflater.inflate(R.layout.my_header, null);
} else {
return (View) layoutInflater.inflate(R.layout.my_row, null);
}
}
Then on bindView:
@Override
public void bindView(final View view, final Context context,
Cursor c) {
if (TYPE_HEADER == getItemViewType(c.getPosition())){
// init and set values here e.g. view.findViewById().setText()
} else {
// init and set values here e.g. view.findViewById().setText()
}
}
Am I on the right track here? Because according to my logs, the c.getPosition() in newView gives different result on c.getPosition() in bindView. I'm actually thinking of just overriding the getView() but they said good practice is overriding newView and bindView in CursorAdapter.
cursor.getPosition() == 0
causes multiple rows to contain the special view. I am guessing this is due to how Cursor adapter tries to be more efficient, just grabbing small groups of data at a time. – Rule