【发布时间】:2012-11-06 09:04:50
【问题描述】:
我的 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 行。
【问题讨论】:
-
当您更改数据时,在执行此操作后调用 onCreate(savedInstanceState) 方法。
-
我不想重新创建我的整个视图!只需强制特定行完全重新加载,并重新膨胀行布局。