setVisibility for an Imageview of a Grid

Asked

Viewed 192 times

1

I have a grid with an image on each item. On top of each image has another smaller image (visa icon, to say that the item has been selected) only invisible. I’m trying to make when the person gives a long click the smaller image of the item he clicked becomes visible. How to make this part of the item image invisible when clicked?

I’ve tried this but not quite 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 only the image of the first item changes. I know the logic ta wrong, that doing so it will really change only the first item, but as I’m still learning Android, I’m not able to make it visible only to the pressed item...

How do I get him to pick up the exact position? (he’s capturing the right position, I’ve checked log. d with position, the problem is when to get the correct image, since I didn’t mention any position, and I don’t know how to do that)

1 answer

1


You say you’re wearing one GridView but the code refers to a listView. I will assume that it is only a variable name error.

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

Replace this code line:

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

for this:

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

I hope this is what you want.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.