你正确实施吗
getItemViewType (int position) ?
从Android的文档中看到:
Returns
An integer representing the type of View. Two views should share the same type if one can be converted to the other in getView(int, View, ViewGroup). Note: Integers must be in the range 0 to getViewTypeCount() – 1. IGNORE_ITEM_VIEW_TYPE can also be returned.
所以也许convertView总是为null,因为适配器不知道哪些项属于一起,所以它不知道哪些项被传递回来…
试试这个:
@Override
public int getItemViewType(int position) {
if (((MyItem)getItem(position)).isHeader()) {
return 1;
} else {
return 0;
}
}
@Override
public int getViewTypeCount() {
return 2;
}
您在getItemViewType中返回的索引只是将标题和非标题组合在一起的标识符.
在这种情况下,您必须在模型项中实现方法“isHeader”(或类似).