I would like to ask why CursorAdapter
splits the process of creating a view and populating it with data into newView()
and bindView()
while BaseAdapter
only does this with getView()
?
From Source code of CursorAdapter.java, CursorAdapter
extends BaseAdapter
.
And you can see getView()
function implementation:
public View getView(int position, View convertView, ViewGroup parent) {
if (!mDataValid) {
throw new IllegalStateException("this should only be called when the cursor is valid");
}
if (!mCursor.moveToPosition(position)) {
throw new IllegalStateException("couldn't move cursor to position " + position);
}
View v;
if (convertView == null) {
v = newView(mContext, mCursor, parent);
} else {
v = convertView;
}
bindView(v, mContext, mCursor);
return v;
}
Its do what we usually do in getView()
(inflate the view if convertView is null, otherwise reuse the view), so its just for make it easier for the developer OR force the user to use ViewHolder pattern.
PS: Some devs calls bindViews() function in there newView() implementation, from the source code you can see there is no need for that.