8

ViewHolder 模式提高了 ListView 滚动帧率,如下例所示: https ://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html

是否可以在对不同行使用不同类型的视图时保持这种模式?

换句话说,是否可以执行以下操作:

 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);  
4

1 回答 1

18

是的,尽管在您的适配器中覆盖getViewTypeCount()和要好得多。getItemViewType()这将教会 Android 的对象池只将一排正确类型的getView().

于 2010-01-17T16:57:02.267 回答