I want to create a listview where each element has several imageview, but they will never be shown together; they will be shown according to the data they want to describe.
This is a part of the element layout
<ImageView
style="@style/release_item_resolution_pic"
android:id="@+id/release_res_standard"
android:layout_alignLeft="@+id/release_label_title"
android:src="@drawable/format_standard" />
<ImageView
style="@style/release_item_resolution_pic"
android:id="@+id/release_res_720p"
android:layout_toRightOf="@+id/release_res_standard"
android:src="@drawable/format_720p" />
<ImageView
style="@style/release_item_resolution_pic"
android:id="@+id/release_res_webdl"
android:layout_toRightOf="@+id/release_res_720p"
android:src="@drawable/format_webdl" />
<ImageView
style="@style/release_item_resolution_pic"
android:id="@+id/release_res_dvdrip"
android:layout_toRightOf="@+id/release_res_webdl"
android:src="@drawable/format_dvdrip" />
Keep in mind that every element has its visibility set to “gone”.
To set which picture show I use this loop, into the getView() method:
for(VideoFormat format:selectedRel.getResolutions()){
ImageView resolutionPic=getResolutionImageView(format, contentView);
resolutionPic.setVisibility(View.VISIBLE);
}
and it works fine, except when I scroll the list and then get back to the first elements. It looks like the list loads other pictures, even if it’s not supposed to; after some times the uncesessary pictures disappear, but it takes too much time. What can I do to avoid all this, and always get the right picture visible?
EDIT:
This is the getResolutionImageView method:
private ImageView getResolutionImageView(VideoFormat format, View contentView){
switch(format){
case BDRIP:
return (ImageView)contentView.findViewById(R.id.release_res_bdrip);
case BLURAY:
return (ImageView)contentView.findViewById(R.id.release_res_bd);
case DVDRIP:
return (ImageView)contentView.findViewById(R.id.release_res_dvdrip);
case HD_1080i:
return (ImageView)contentView.findViewById(R.id.release_res_1080i);
case HD_1080p:
return (ImageView)contentView.findViewById(R.id.release_res_1080p);
case HD_720p:
return (ImageView)contentView.findViewById(R.id.release_res_720p);
default:
return (ImageView)contentView.findViewById(R.id.release_res_standard);
case WEB_DL:
return (ImageView)contentView.findViewById(R.id.release_res_webdl);
}
}
When list view scrolls it’s
getViewmethod called. But theconvertViewwhich it gets may contains old data. (data of other list rows).So here is the solution
in
getViewmethod when you set theVisibilityof one image, setInvisibleof all other ImageViews.