【发布时间】:2012-11-27 18:30:29
【问题描述】:
我有一个自定义的 ExpandableListAdapter,我在其中指定了 getGroup(...),如下所示:
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
//do stuff
if(something) {
if (convertView == null) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.tasks_list_group_with_child, null);
}
TextView taskNameText = (TextView) convertView.findViewById(R.id.tlgwc_task_name);
//do stuff
} else {
if (convertView == null) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.tasks_list_group_without_child, null);
}
TextView taskNameText = (TextView) convertView.findViewById(R.id.tlgwoc_task_name);
//do stuff
}
return convertView;
}
现在的问题是,当我更改在适配器中使用的数据时,getGroup(...) 方法的参数(被重用的视图对象)“convertView”可能不再具有正确的布局.如何检查它是具有 R.layout.tasks_list_group_without_child 还是 R.layout.tasks_list_group_with_child 布局的视图?
正如 API 所说的“convertView:如果可能的话,要重用的旧视图。您应该在使用前检查此视图是否为非空且类型合适”,但如何操作?!
【问题讨论】:
标签: android layout view expandablelistadapter