次のように getGroup(...) を指定したカスタム ExpandableListAdapter があります。
@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: 可能であれば再利用する古いビュー。使用する前に、このビューが null ではなく、適切なタイプであることを確認する必要があります」が、どのように?!