Lit*_*ild 4 android baseadapter android-cursoradapter
我想问为什么CursorAdapter将创建视图并用数据填充它的过程拆分为newView()并且bindView()只BaseAdapter执行此操作getView() ?
从CursorAdapter.java的源代码中,CursorAdapter扩展了BaseAdapter。
可以看到getView()函数的实现:
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;
}
Run Code Online (Sandbox Code Playgroud)
它做我们通常做的事情getView()(如果convertView为null则膨胀视图,否则重用视图),所以它只是为了让开发人员更容易或强制用户使用ViewHolder模式。
PS:有些开发者在newView()实现中调用bindViews()函数,从源代码中可以看到没有必要。
| 归档时间: |
|
| 查看次数: |
1874 次 |
| 最近记录: |