我的代码从listview项目中的url加载图像,如
HorizontalListView listview = (HorizontalListView) view
.findViewById(R.id.listview);
HorizontalListViewAdapter horizontalListViewImageAdapter = new HorizontalListViewAdapter(
getActivity(), allMovies, res);
listview.setAdapter(horizontalListViewImageAdapter);
那些单元格在屏幕上可见,显示图像非常正确,但是当我滚动列表时,它会消失图像。一些图像变得不可见,直到我刷新片段,一旦片段刷新它就能很好地工作。
用于下载图像我在适配器类中使用ImageLoader。如果您了解此案,请提供帮助。感谢
这是适配器代码
public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
final ViewHolder holder;
if (convertView == null) {
vi = inflater.inflate(R.layout.horizontal_listviewitem, parent,
false);
holder = new ViewHolder();
holder.image = (ImageView) vi.findViewById(R.id.horizontal_image);
holder.progressBar = (CircularProgressBar) vi
.findViewById(R.id.progress_bar_horizontal_item);
vi.setTag(holder);
} else
holder = (ViewHolder) vi.getTag();
if (data.size() <= 0) {
// holder.price.setText("No Data Found");
} else {
productData = null;
productData = (Movies) data.get(position);
try {
ImageLoader.getInstance().displayImage(
"http://" + ControllerConstants.IP_ADDRESS + ""
+ productData.getThumbnail(), holder.image,
Utility.options, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String arg0, View arg1) {
// TODO Auto-generated method stub
holder.progressBar.setIndeterminate(true);
}
@Override
public void onLoadingFailed(String arg0, View arg1,
FailReason arg2) {
// TODO Auto-generated method stub
holder.progressBar.setIndeterminate(false);
}
@Override
public void onLoadingComplete(String arg0,
View arg1, Bitmap arg2) {
// TODO Auto-generated method stub
holder.progressBar.setIndeterminate(false);
}
@Override
public void onLoadingCancelled(String arg0,
View arg1) {
// TODO Auto-generated method stub
holder.progressBar.setIndeterminate(false);
}
});
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
return vi;
}