setVisibility for an ImageView of a Grid

1

I have a grid with an image in each item. On top of each image has another smaller image (visa icon, to say that the item was selected) only invisible. I'm trying to make when the person a long click the smaller image of the item he clicked is visible. How do you make this part of the item image invisible when clicked?

I tried this but it was not right

listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                Log.d("CLICK", "LONG CLICK");
                selectedImageView = (ImageView) findViewById(R.id.selectedImageView);
                selectedImageView.setVisibility(View.VISIBLE);
                return true;
            }
        });

So just the image of the first item changes. I know the logic is wrong, that doing so it will really only change the first item, but as I am still learning Android, I am not able to make it visible only to the item pressed ...

How do you get the exact position? (it's capturing the right position, I've already checked log.d with position, the problem is when I get the correct image, since I did not mention any position, and I do not know how to do that)

    
asked by anonymous 03.08.2014 / 08:55

1 answer

1

You say that you are using GridView but the code refers to listView . I'm assuming it's just a variable name error.

The View that was clicked is passed to onItemLongClick in the variable view that appears in the method declaration. Use it by using the findViewById method of this object: view .findViewById (..) ;, to access the items contained in it.

Replace this line of code:

selectedImageView = (ImageView) findViewById(R.id.selectedImageView);  

by this:

selectedImageView = (ImageView) view.findViewById(R.id.selectedImageView);  

I hope this is what you want.

    
03.08.2014 / 14:45