After searching an trying how to do it, I put this question due to my failures.
The point is I am trying to show in a Gallery several pictures that I get from a http server. The thing is when I open the activity for first time, if the picture is not in a specific folder, local cache, I display a default picture and them I launch a download of the picture by a AsyncTask. What I try is as soon as the picture has been downloaded and save in the folder, to update/refresh the gallery in the activity to display the picture. If I slip left/right the gallery the picture appear when the gallery is refresh, but I want this happen avoiding to slip the gallery.
Also comment that the base adapter is all the time with the right reference to the picture, the default picture is selected if the file does not exist in the folder.
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageBitmap(getPicturePath(position + 1));
i.setLayoutParams(new Gallery.LayoutParams(wHeight / 3, wHeight / 4));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
private Bitmap getPicturePath(int picture) {
String picturePath = Environment.getExternalStorageDirectory()
.getAbsolutePath()
+ "/pictures/" + picture
+ ".jpg";
File f = new File(picturePath);
if (f.exists())
return BitmapFactory.decodeFile(picturePath);
else
return BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.no_image);
}
I try to invalidate() in the gallery and also notifyDataSetChanged() in the adapter, baseadapter, but it does not work, the pictures on the screen do not change.
Any suggestion how to solve this?
Many thanks.