Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetView Vs. BindView in a custom CursorAdapter?

So, I'm watching this video http://www.youtube.com/watch?v=N6YdwzAvwOA and Romain Guy is showing how to make more efficient UI adapter code using the getView() method. Does this apply to CursorAdapters as well? I'm currently using bindView() and newView() for my custom cursor adapters. Should I be using getView instead?

like image 739
Christopher Perry Avatar asked Aug 20 '10 21:08

Christopher Perry


2 Answers

CursorAdapter has an implementation of getView() that delegates to newView() and bindView(), in such a way as enforces the row recycling pattern. Hence, you do not need to do anything special with a CursorAdapter for row recycling if you are overriding newView() and bindView().

like image 108
CommonsWare Avatar answered Sep 21 '22 07:09

CommonsWare


/**      * @see android.widget.ListAdapter#getView(int, View, ViewGroup)      */     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;     } 

This CursorAdapter source code, clearly cursorAdapter work more.

like image 42
Crossle Song Avatar answered Sep 20 '22 07:09

Crossle Song