0

I have a custom gridview.

In that, am using a frame layout which contains a image button, textview and a view. I need to change the background color of imageview/ text color of textview and drawable of view when an item is pressed.

In order to achieve that, I performed setOnClickListener inside that adapter. And to undo the changes i implemented setOnLongClickListener.

Now the question is, I want to change background color and all for only one item at a time. How do I achieve that? If item1 was selected previouslt,it should be unselected when I click on item2.

Let's say I store the position of item which has been clicked, how do I perform setOnLongClickListener for the item on that position when another item is clicked?

Item1   Item2   Item3   Item4
 Y       N       N       N

Position :0

Now after clicking on Item2,

Item1   Item2   Item3   Item4
 N       Y       N       N

I need to perform onlongClicklistener for that position.
driftking9987
  • 1,673
  • 1
  • 32
  • 63
  • I faced same problem and I searched this answer try this answer [enter link description here](http://stackoverflow.com/a/13880851/2774275) – Out Of Bounds May 12 '16 at 18:58
  • The link talks about the onClick event for things inside a childitem. That's am doing anyway. I need to perform onLongClick for a item at a position which is known to me when I click on another item. – driftking9987 May 12 '16 at 19:01

1 Answers1

0

I searched another answer for you but it is in list view you can change yourself to grid view see this link

Community
  • 1
  • 1
  • If I perform onClick event for the image button in the adapter, am able to change the background color. So everytime I press a item, the color is being changed so multiple items are being selected and that is exactly which I don't want. I want the color of item to be reverted back to original when I click on another item. – driftking9987 May 12 '16 at 19:23