Hi all,
I have a gridView where I want to be able to toggle the item icons
when clicking them. So, when I click an item it gets "selected" which
is indicated by, say, bitmap B and when I click it again it should be
"unselected" and the item changes back to bitmap A.

The problem is that I cannot get the grid to redraw after I have
clicked one of the items so the clicked item never changes icon. I
have tried to call requestLayout() but for some reason it only results
in a two successive calls to the adaptor's getView(), both with
position zero regardless of which item I clicked. What am I missing
here?

Here are some code snippets:

>>>
...
final GridView myGrid = (GridView) findViewById(...);
...
myGrid.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
            @Override
            public void onItemClick(AdapterView<?> parent,
                    View view,
                    int position,
                    long id)
            {
                // Toggle icon.
                toggleIconState(position);

               myGrid.requestLayout();
            }
        });

>>> From my adaptor class (The getIcon() returns one of two bitmaps depending 
>>> on a state var. (selected/unselected))

 @Override
    public View getView(int position, View convertView, ViewGroup
parent)
    {
        ImageView imageView;

        if (convertView == null)
        {
            // Create the image view if we aren't recycling an old
view.
            imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        }
        else
        {
            imageView = (ImageView) (convertView);
        }

        // Use this position's asset group icon as the image view
contents.
        imageView.setImageBitmap(getIcon(position));
        return imageView;
    }


Any ideas are most welcome.

Thanks,
Rickard

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to