I have an Activity which extends ExpandableListActivity and which contains some Parent Groups and some Child Entries…
Left of the entries inside the groups i put an icon. Whenever I open an entry it randomly takes out icons and it’s not showing them anymore… I couldn’t find a pattern there so I’m not quite sure where my mistake is (Maybe I am recycling my objects the wrong way?!)
Here is my BaseExpandableListAdapter:
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) myContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.child_row, null);
}
TextView tvName = (TextView) convertView.findViewById(R.id.tvName);
tvName .setText(arrChildelements[groupPosition][childPosition]);
ImageView tvIcon = (ImageView) convertView.findViewById(R.id.imageViewIcon);
switch (childPosition) {
case 0:
tvIcon.setImageResource(R.drawable.ic_1);
break;
case 1:
tvIcon.setAlpha(0);
break;
case 2:
tvIcon.setImageResource(R.drawable.ic_2);
break;
case 3:
tvIcon.setImageResource(R.drawable.ic_3);
break;
case 4:
tvIcon.setImageResource(R.drawable.ic_4);
break;
case 5:
tvIcon.setImageResource(R.drawable.ic_5);
break;
case 6:
tvIcon.setImageResource(R.drawable.ic_6);
break;
}
return convertView;
}
And here is my child_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageViewIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="40dp"
android:src="@drawable/empty" />
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:autoLink="all"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textSize="18sp" >
</TextView>
</LinearLayout>
If you need any additional information and/or code, please let me know!
Thanks in advance for your help and please excuse my english…
it because
tvIcon.setAlpha(0);andListViewoptimalization …you should set alpha to 1 in other cases (
tvIcon.setAlpha(1);before switch statment)…Edit:
or instead
tvIcon.setAlpha(0);trytvIcon.setImageResource(R.drawable.empty);