您的位置:首页 > 其它

SimpleCursorAdapter ---的学习

2010-04-09 12:06 197 查看
以前对newview 和bindview的理解不是很深,今天特意研究研究。

newView    0
bindView    0
newView    1
bindView    1
newView    2
bindView    2
newView    3
bindView    3
newView    4
bindView    4
newView    5
bindView    5
newView    6
bindView    6
newView    7
bindView    7


开始时有多少可以显示的view就执行下多少下newView,后面滚动listview的时候 只执行bindView,除非又可以看到新的item如上面的如果可以看到第8个item的时候,那就要newView.否则都不执行newView,下面是listview滚动的时候的执行log.

bindView    8
bindView    9
bindView    10
bindView    11
bindView    12
bindView    13
bindView    14
bindView    15


class QueryHandler extends AsyncQueryHandler {
QueryHandler(ContentResolver res) {
super(res);
}
@Override
protected void onQueryComplete(int token, Object cookie,
Cursor cursor) {
// Log.i("@@@", "query complete: " + cursor.getCount() + "   " +
// mActivity);
if (cursor != null) {
System.out.println("onQueryComplete.......");
}
mActivity.initCursor(cursor);//更新adpter
}
}


onQueryComplete()-->当AsyncQueryHandler async async.startQuery()后面的时候就会执行onQueryComplete().这个时候来更新listview.调用adapter.changeCursor(newCursor)-->cursor变化的时候来控制更新adpter.

总结:

一般情况SimapleCursorAdapter是用来和数据库有关cursor,AsyncQueryHandler 的运用。一般newView中只负责View的部分,setTag(View)-->只对view,对数据的处理都放在bindView中,不然会有异常情况出现!因为newView在listView滚动的情况下大部分时间不执行,除非上面所说的!总的来说android的用这个就实现了界面更新时候只是更新了数据。而view还是和以前一样。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: