ListView Display

本文详细解析了AbsListView的onMeasure、obtainView、CursorAdapter中的getView和bindView方法,阐述了如何通过适配器(如CursorAdapter)展示ListView内容的原理,包括获取视图、创建视图和绑定数据的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How can adapter display the content of the listview.

1.AbsListView.java

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      .......
      final View child = obtainView(0, mIsScrap);
      .....
    }
//one item, called one time.
2.AbsListView.java

    View obtainView(int position, boolean[] isScrap) {
....
child = mAdapter.getView(position, scrapView, this);
....
}

3.CursorAdapter.java

    public View getView(int position, View convertView, ViewGroup parent) {
        .....
        if (convertView == null) {
            v = newView(mContext, mCursor, parent);
        } else {
            v = convertView;
        }
        bindView(v, mContext, mCursor);
        return v;
    }

4.CursorAdapter.java

    public abstract void bindView(View view, Context context, Cursor cursor);
    public abstract View newView(Context context, Cursor cursor, ViewGroup parent);

//so override the the bindView and newView. and we just need the return the item view not the listview. 

all adapters getView

   View getView(int position, View convertView, ViewGroup parent);
so for what adapter, we just need to return one item's view.



file to url

    public static Uri fromFile(File file) {
        if (file == null) {
            throw new NullPointerException("file");
        }

        PathPart path = PathPart.fromDecoded(file.getAbsolutePath());
        return new HierarchicalUri(
                "file", Part.EMPTY, path, Part.NULL, Part.NULL);
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值