Skip to content

Instantly share code, notes, and snippets.

@mustafasevgi
Created February 26, 2015 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafasevgi/f4c0ce40105fc7ced93e to your computer and use it in GitHub Desktop.
Save mustafasevgi/f4c0ce40105fc7ced93e to your computer and use it in GitHub Desktop.
Adapter load image and change view visibility in asynctask
// Using an AsyncTask to load the slow images in a background thread
new AsyncTask<ViewHolder, Void, Bitmap>() {
private ViewHolder v;
@Override
protected Bitmap doInBackground(ViewHolder... params) {
v = params[0];
return mFakeImageLoader.getImage();
}
@Override
protected void onPostExecute(Bitmap result) {
super.onPostExecute(result);
if (v.position == position) {
// If this item hasn't been recycled already, hide the
// progress and set and show the image
v.progress.setVisibility(View.GONE);
v.icon.setVisibility(View.VISIBLE);
v.icon.setImageBitmap(result);
}
}
}.execute(holder);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment