您需要让适配器的视图回收器知道不止一种布局,以及如何区分每一行的两种布局。只需覆盖以下方法:
@Overridepublic int getItemViewType(int position) { // Define a way to determine which layout to use, here it's just evens and odds. return position % 2;}@Overridepublic int getViewTypeCount() { return 2; // Count of different layouts}合并
getItemViewType()进来
getView(),像这样:
if (convertView == null) { // You can move this line into your constructor, the inflater service won't change. mInflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); if(getItemViewType(position) == 0) convertView = mInflater.inflate(R.layout.listview_item_product_complete, parent, false); else convertView = mInflater.inflate(R.layout.listview_item_product_inprocess, parent, false); // etc, etc...观看Android的Romain Guy 在Google
Talks上讨论视图回收器。



