views:

431

answers:

2

I have a GridView, using a custom adapter (myAdapter extends BaseAdapter), where each item in the grid holds an ImageButton. getView() is working fine.

However, from elsewhere in my code, how can I update the image (setImageResource) for one particular item in the grid based on its position in the GridView?

So far, I've added this to my adapter class:

public void changeImage() {
        Log.d(TAG, "Image change");
        this.ImageButton.setImageResource(R.drawable.newImage);
}

And would like to write something like this: mygridview.getItemIdAtPosition(20).changeImage(); (doesn't compile).

A: 

Hey did u get the solution for this? I have a gridview and i want to shift the images of one row to another row of grid after a particular time...is it possible???

Pria
I'm afraid I didn't get an answer. But I think you probably want to update your data source and then update the adapter?
Chris
I found the solution...Thanks..!
Pria
Would you care to post it?
Select0r
A: 

If u want to update the image for one particular item in the grid, what u can do is...have an onClickListener for all the images in the grid.

Now when u will click on any of the image, get the position of the image and change ur background resource for that particular image.

Example:

While adding the image: imageView.setOnClickListener(imageListener);

And the listener will be something like dis:

private OnClickListener imageListener = new OnClickListener() {
        public void onClick(View v) {
            int id = v.getId();
            ImageView imgView = imageArray.get(id);
            imgView .setBackgroundResource(R.drawable.newImage);
    };

I hope u find it helpful.

Pria