我可以将图像添加到我的ListView
并且它们可以显示,但是如果列表中的项目超过 8 个,则会ListView
显示该项目的错误图像。这是我的newView()
方法:
public View newView(Context context, Cursor cursor, ViewGroup parent){
final LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(layout, parent, false);
try{
int count = cursor.getCount();
String image = cursor.getString(cursor.getColumnIndex(RecipeClasses.Recipe.RECIPE_IMAGE));
String recipe_name = cursor.getString(cursor.getColumnIndex(RecipeClasses.Recipe.RECIPE_NAME));
Uri path = Uri.parse(image);
TextView recipe_txt = (TextView) view.findViewById(R.id.txt_recipe_row);
ImageView img = (ImageView) view.findViewById(R.id.img_view_recipe);
if (new File(image).exists()) {
ImageResizer img_W = new ImageResizer(context, img.getMeasuredWidth(), img.getMeasuredHeight());
img_W.loadImage(image, img);
} else {
ImageResizer img_W = new ImageResizer(context, img.getMeasuredWidth(), img.getMeasuredHeight());
img_W.loadImage(path, img);
img.setImageURI(path);
}
if (recipe_txt != null){
recipe_txt.setText(recipe_name);
}
} catch (Exception e){
// TODO: handle exception
}
return view;
}