I am trying to develop an Android application that allows the user to retrieve data from flickr and display it in a GridView (with some nice 3D animation). After some adventures, I almost ran, but now I'm stuck.
Here's the problem:
I got a user interface called "LoadPhotosTask" that receives images from flickr, just like the open source photostream application. In the onProgressUpdate(LoadedPhoto... value) method of this subclass, I call addPhoto() . So far, everything is in order - I have good Bitmap and Flickr.photo data with all the necessary information.
@Override public void onProgressUpdate(LoadedPhoto... value) { addPhoto(value); }
On the other hand, I have a GridView . Now I want to fill it with photos. It has an adapter called ImageAdapter (which extends BaseAdapter , see this tutorial ). If I use an array inside the ImageAdapter class, I can populate the GridView several samples. But if I want to fill it at runtime, I don't know what to do.
How do I configure the getView method in the ImageAdapter ? I tried to fill the array inside the ImageAdapter class ImageAdapter my values ββin addPhoto , but it does not display anything.
So, first of all, I set up an array with the number of photos that I wanted to display in the grid (code inside the ImageAdapter class):
Then I call this method with the length of my photo sheet:
final Flickr.PhotoList list = params[0]; final int count = list.getCount(); int helper = 0; imagead.setupArray(count);
Subsequently, I manually call the getView method inside the addPhoto method:
private void addPhoto(LoadedPhoto... value) { ImageView image = (ImageView) mInflater.inflate( R.layout.grid_item_photo, null); image.setImageBitmap(value[0].mBitmap); image.setTag(value[0].mPhoto); imagead.setmThumbIds(image, value[0].mPosition); imagead.getView(value[0].mPosition, null, mpicturesGrid); }
This is the getView method inside the ImageAdapter:
public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { // if it not recycled, initialize some // attributes imageView = new ImageView(mContext); imageView.setLayoutParams(new GridView.LayoutParams(EDGE_LENGTH, EDGE_LENGTH)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(0, 0, 0, 0); imageView.setVisibility(View.VISIBLE); } else { imageView = (ImageView) convertView; } imageView.setImageDrawable(mThumbIds[position].getDrawable()); imageView.setTag(mThumbIds[position].getTag()); return imageView; }