gpt4 book ai didi

android - 为什么 CursorAdapter 与 BaseAdapter 不同?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:39:00 25 4
gpt4 key购买 nike

我想问一下为什么 CursorAdapter 将创建 View 和用数据填充它的过程拆分为 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;
}

它做我们通常在 getView() 中做的事情(如果 convertView 为 null,则膨胀 View ,否则重用 View ),所以它只是为了让开发人员更容易或强制用户使用 ViewHolder 模式。

PS:一些开发者在 newView() 实现中调用了 bindViews() 函数,从源代码中可以看出没有必要。

关于android - 为什么 CursorAdapter 与 BaseAdapter 不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18561744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com