views:

38

answers:

1

Hi, The sample code of hello-gridview implements an image adapter to populate the gridview with a series of customized imageviews. the getview method in image adapter is implemented to customize image views. I am wondering how this method is utilized to populate the gridview. It looks like that the population is based on the integer array in the image adapter. If there are two integer arrays what will happen? Could you pleas talk about the detail steps for the gridview population process?

One more question is about the getitem(position) method in the image adapter. this method is supposed to return the corresponding data item of the imageadapter. It returns null in the sample code.How could we implement the getitem(position) method to return a specific customized child imageview of the gridview?

Many thanks,

Song

A: 

In that example the images are hard-coded to application resources and the array is just a holder for the resource ids. In this example if there were two integer arrays, it will still use the mThumbIds array in getView() to determine the integer ids to use.

In your Adapter you will need to specify the data. In this example the data is drawables in the application resources. In the built-in Gallery App it is images on the sdcard, In the Launcher menu it is install applications, in your case it could be included resources, files on the sdcard, or data you fetch from a remote server. You are responsible for populating the adapter with the data.

The getView() method returns the child view for the specified grid item. The getItem() method returns some data associated with a specified position in the data set and in most cases it is okay for it to return null.

BrennaSoft
Do you mean if I want to get a child view of the gridview I need to call getview() method instead? If yes, what is the convertview paramter?if no, what is the way to get the childview of the gridview?thanks
song
No. You don't need to do anything. You just have to implement the adapter correctly. The GridView calls getView() for each item it needs to display.
BrennaSoft
My question is about how to get control of these child image views.for example if I would like to add some animation effect for a specific child imageview, how can i get the imageview?thanks
song