Reputation: 1925
This question is often asked here .Lot of people got the solution and working also. I am also facing the same problem, My gridview onitemclick listner not working.
In my case
I have a viewpager.
Inside that I have fragments. On those fragments I have Gridview. Setting onItemclick listner to grid view not working, tried all case which I found on internet.
This viewpager is itself added in a sepratefragment. See the Picture For better Understanding. The code is almost simple so not adding here for reference. Where I could be wrong. if not how to hack this
Working case: I am getting pressed events when i am adding onclicklistner to buttons in adapter. But not able to update the button text, when calling notifydatasetchanged.
Upvotes: 0
Views: 441
Reputation: 16120
Sounds like you have buttons inside your gridView adapter. Having buttons, checkboxes etc.. inside the adapter itemView will cause the actual row not to respond to onItemClick events. There are some solutions you would find in fixing this, but what i would suggest is to add a onClickListener
to the row (contentView
) inside the getView()
method of the adapter and handle what you need there. You can pass the position of the clicked view either by a constructor (if you implement the onClickListener
into a class which you use for the setOnClickListener
or set the position to final in getView
and use an anonymous class for the setOnClickListener
method call.
If you need to do something based on this click back into the fragment read a bit on how to create a callback with the help of an interface.
Upvotes: 2