我的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行。