短信小程序,关于CursorAdapter视图复用问题

问题:我要现实的item个数为13个,然后CursorAdaper却只给我new了6次


从而导致显示结果如下:

百思不得其解,查看了源码,只有在View为空的时候才会new,不为空的时候则复用,故我的解决方法是,重写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(),让其每一次都new一个View

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    getCursor().moveToPosition(position);
    View view = newView(mContext, getCursor(), parent);
    bindView(view,mContext,getCursor());
    return view;

}
嗯哼,记录一下这个问题

猜你喜欢

转载自blog.csdn.net/qq_37707251/article/details/80359861
今日推荐