In my Android application an Asyntask is used for loading images from web in a list view.I want to show the center portion of the image and I have tried imageloader for loading images but the problem is image clarity is very poor but I have used it for loading thumbnails because thumbnail is very small.So that I have tried an Asyntask which is given below.The problem with this method is image view shows other images that means image view in first list item will show the next list item's image and after some time it will display the correct image.How can I solve this issue.Or suggest a method for lading images with good clarity.Please help me.Thanks in advance
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
ProgressBar mProgressBar;
String url;
public DownloadImageTask(ImageView bmImage, ProgressBar progressBar) {
this.bmImage = bmImage;
this.mProgressBar = progressBar;
}
@Override
protected void onPreExecute() {
mProgressBar.setVisibility(View.VISIBLE);
super.onPreExecute();
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
url = urldisplay;
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
// Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
Utilities.addBitmapToMemoryCache(url, result);
bmImage.setImageBitmap(result);
mProgressBar.setVisibility(View.GONE);
// result.recycle();
}
}
}
public View getView(final int position, View convertView, ViewGroup parent) {
vi = convertView;
int type = getItemViewType(position);
// Utilities.message_player = new MediaPlayer();
if (vi == null) {
inflater = LayoutInflater.from(mcontext);
if (type == ITEM_TYPE_ONE)
vi = inflater.inflate(R.layout.message_group_list_item, null);
else
vi = inflater.inflate(R.layout.listlastrow, null);
}
if (type == ITEM_TYPE_ONE) {
if (fontType == true) {
}
((ImageView) vi.findViewById(R.id.imageMessage)).setTag(position+"i");
Bitmap bmp = Utilities.getBitmapFromMemCache(feedsImage);
if(bmp == null){
DownloadImageTask dwnloadImgTask = new DownloadImageTask(((ImageView) vi.findViewWithTag(position+"i")),
((ProgressBar) vi.findViewById(R.id.progressBar1)));
dwnloadImgTask.execute(feedsImage);
}else{
((ImageView) vi.findViewById(R.id.imageMessage)).setImageBitmap(bmp);
}
}
}