我的 ListAdapter 中有以下代码
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View childView, ViewGroup parent)
{
I dataItemForChild = null;
if (childPosition >= dataModel.size())
{
// its an extra row
}
else
{
dataItemForChild = (I) getChild(groupPosition, childPosition);
}
boolean isEvenRow = (childPosition % 2 == 0);
if (childView == null)
{
final HashMap<Integer, View> viewMap = new HashMap<Integer, View>();
childView = inflateChildView(isLastChild, isEvenRow, childPosition, groupPosition, dataItemForChild);
childView.setTag(viewMap);
addViewMappingCache(viewMap, childView);
populateChildView(isLastChild, isEvenRow, childPosition, groupPosition, dataItemForChild, childView, viewMap);
}
else
{
populateChildView(isLastChild, isEvenRow, childPosition, groupPosition, dataItemForChild, childView, (HashMap<Integer, View>) childView.getTag());
}
return childView;
}
问题是我有不同的布局用于列表中的不同行。当我更新数据然后调用 adapter.notifyDataChanged() 时,由于 childView 不为 null,它不会再次调用 inflateChildView,因此某些行上的布局不再与数据所需的布局匹配。
有没有办法使特定行“无效”或清除其布局缓存,使其传入的 childView 为空?
我试图实现的具体用例是最后一行,上面写着“加载更多”。再次加载后,我希望用数据行替换 LoadMore 行,然后(如果有的话)新的最后一行应该是 LoadMore 行。