Android:ViewHolder模式和不同类型的行?

tom*_*ash 8 performance android listview reusability listadapter

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);  
Run Code Online (Sandbox Code Playgroud)

Com*_*are 17

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