I wrote an implementation of BaseExpandableListAdapter which overrides as well the getChildType and getChildView methods. There are 10 Groups, 4 of them have children.
The following implementation works on the emulator and on tested htc devices. That means:
When I open GROUP_W visually, the convertView paramter of getChildView(...) is correctly null the first time and reuses the view later.
This implementation does not work on Samsungs Galaxy S3 and the Galaxy Tab. That means: When I open GROUP_W visually, the convertView paramter of getChildView(...) is not null the first time and provides a wrong view which leads further to an exception.
@Override
public int getChildType(int groupPosition, int childPosition) {
switch (groupPosition) {
case GROUP_W:
return 0;
case GROUP_X:
case GROUP_Y:
return 1;
case GROUP_Z:
return 2;
default:
// actually not used
return super.getChildType(groupPosition, childPosition);
}
}
@Override
public int getChildTypeCount() {
return 3;
}
When i change the implementation to following, without seeing any logical reason, then it works on the Samsung devices as well.
@Override
public int getChildType(int groupPosition, int childPosition) {
switch (groupPosition) {
case GROUP_W:
return 1;
case GROUP_X:
case GROUP_Y:
return 2;
case GROUP_Z:
return 3;
default:
return super.getChildType(groupPosition, childPosition);
}
}
@Override
public int getChildTypeCount() {
return 4;
}
Does anyone have this strange behaviour as well, or does anybody understand what i am doing or what is going wrong? Thanks a lot ;)
Edit: Added getChildView()
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
Context context = parent.getContext();
switch (groupPosition) {
case GROUP_W:
X x = arrayX[childPosition];
return ListItemFactory.getTwoLineListItemTextIndicatorTopRight(context, x.getString1(), x.getString2(), x.getString3(), convertView);
case ...
default:
return null;
}
}
public static View getTwoLineListItemTextIndicatorTopRight(Context context, CharSequence line1, CharSequence line2,
CharSequence indicator, View convertView) {
View view;
if (convertView == null) {
view = View.inflate(context, R.layout.two_line_list_item_textindicator_topright, null);
}
else {
view = convertView;
}
// here happens a null pointer exception because textView1 is not available in the wrong convert view
((TextView) view.findViewById(R.id.textView1)).setText(line1);
((TextView) view.findViewById(R.id.textView2)).setText(line2);
if (indicator == null || indicator == "") {
((TextView) view.findViewById(R.id.textViewIndicator)).setVisibility(View.GONE);
}
else {
TextView textView = ((TextView) view.findViewById(R.id.textViewIndicator));
textView.setText(indicator);
textView.setVisibility(View.VISIBLE);
}
return view;
}