为什么从BaseAdapter的CursorAdapter有什么不同? [英] Why is CursorAdapter different from BaseAdapter?

查看:197
本文介绍了为什么从BaseAdapter的CursorAdapter有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下为什么的CursorAdapter 拆分创建一个视图,并用数据填充到 NewView的() bindView(),而 BaseAdapter getView()

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() ?

推荐答案

从<一个来源$ C ​​$ C href=\"https://github.com/android/platform_frameworks_support/blob/master/v4/java/android/support/v4/widget/CursorAdapter.java\"相对=nofollow> CursorAdapter.java ,的CursorAdapter 扩展 BaseAdapter 。结果
你可以看到 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;
    } 

它做什么,我们通常做的 getView()(膨胀的观点,如果convertView为空,否则重用视图),因此它只是为了更容易的开发商或强制用户使用ViewHolder格局。

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:有些开发者调用bindViews()函数在那里NewView的()执行,从源头code,你可以看到有没有必要的。

PS: Some devs calls bindViews() function in there newView() implementation, from the source code you can see there is no need for that.

这篇关于为什么从BaseAdapter的CursorAdapter有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆