Я хочу загрузить изображение на listview, я могу загрузить изображение с URL-адреса и показать в списке, но скорость очень медленная. Как я могу повысить скорость загрузки? , пожалуйста, помогите мне. я использовать этот код для загрузки изображения из URL:Загрузка изображения, но медленная скорость на android
ImageService Класс:
InputStream input = null;
Bitmap bitmap = null;
try {
URL url = new URL(src);
// We open the connection
URLConnection conection = url.openConnection();
conection.connect();
input = new BufferedInputStream(url.openStream(), 8192);
// we convert the inputStream into bitmap
bitmap = BitmapFactory.decodeStream(input);
input.close();
Log.e("ERROR:","OOOOOOOOOK");
} catch (Exception e) {
Log.e("eRROR:", e.getMessage());
}
return bitmap;
}
ProductAdapter класс для таможенных ListView:
private LayoutInflater mInflater;
private List items = new ArrayList();
public ProductAdapter(Context context, List items) {
mInflater = LayoutInflater.from(context);
this.items = items;
}
public int getCount() {
return items.size();
}
public Product getItem(int position) {
return (Product) items.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
Product s = (Product) items.get(position);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.row_layout, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.name);
holder.pic = (ImageView) convertView.findViewById(R.id.image);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.name.setText(s.getName());
if (s.getImage() != null) {
holder.pic.setImageBitmap(s.getImage());
} else {
holder.pic.setImageResource(R.drawable.ic_launcher);
}
return convertView;
}
static class ViewHolder {
TextView name;
ImageView pic;
}
Вы можете видеть из этого поста, Действительно хороший http: //stackoverflow.com/questions/541966/how-do-i-do-a-lazy-load-of-images-in-listview – CodeWarrior