我是android和java的新手。我制作了一个运行良好的应用程序,除了当我向下滚动应用程序中的列表视图时出现 java.lang.OutOfMemoryError 异常,每次滚动到底部时都会动态增加(10 个项目)。滚动一些 4-5 页后,我得到了这个异常。任何人都可以帮我解决此异常以及避免此类异常的一些提示。
我的适配器:
public class LazyAdapter extends BaseAdapter{
private static LayoutInflater inflater = null;
private Activity activity;
public ImageLoader imageLoader;
public static ArrayList<Product> values;
private String product_action;
public LazyAdapter(Activity a, ArrayList<Product> arg3) {
values = arg3;
activity = a;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return values.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView text;
public ImageView image;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
ViewHolder holder;
Product p = values.get(position);
if (convertView == null) {
vi = inflater.inflate(R.layout.feed_items, null);
holder = new ViewHolder();
holder.text = (TextView) vi.findViewById(R.id.label);
;
holder.image = (ImageView) vi.findViewById(R.id.logo);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
if (condition1) {
holder.text.setText(myText);
holder.image.setTag(imageUrl);
imageLoader.DisplayImage(imgURL, activity, holder.image);
} else if (condition2) {
holder.text.setText(myText);
holder.image.setTag(imageUrl);
imageLoader.DisplayImage(imgURL, activity, holder.image);
} else if (condition3) {
holder.text.setText(myText);
holder.image.setTag(imageUrl);
imageLoader.DisplayImage(imgURL), activity,
holder.image);
}
return vi;
}
public void add(Product product) {
values.add(product);
}
}