Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: ViewHolder pattern and different types of rows?

ViewHolder pattern improves ListView scrolling framerate, as seen in following example: https://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html

Is it possible to keep this pattern while using different kind of Views for different rows?

In other words, is it possible to do something like:

 public View getView(int position, View view, ViewGroup parent) {  
     // calculate viewID here
     if (view == null || *view is not null but was created from different XML than viewID* ) { 
         view = mInflater.inflate(viewId, null);  
like image 966
tomash Avatar asked Jan 17 '10 16:01

tomash


1 Answers

Yes, though it is far better to override getViewTypeCount() and getItemViewType() in your Adapter. That will teach Android's object pool to only hand you a row of the proper type back in getView().

like image 111
CommonsWare Avatar answered Oct 27 '22 06:10

CommonsWare