• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Detecting the ID of child view in LinearLayout

szw21

Lurker
Dec 22, 2011
6
0
I'm trying to figure out how to detect the object I've clicked on within a LinearLayout which itself is a child window within a gridview. I've tried a few methods which I thought would work but none of them work. Within the gridview I can detect the correct child window (which in this case is the Linear Layout) but I cannot figure out how to detect the object within the LinearLayout itself.

Any ideas?
 
Thanks for the reply. I have an onItemClick handler for the gridview which returns the clicked childview - in this case if I click the LinearLayout I do get a view to it.

I tried setting up an onClick (via an onClickListener) for the object directly. I tried to create a view to the resource by using findViewById and then using it to register the callback. For some reason I'm getting a null pointer so I'm probably in the code where the object has not yet been created.

Would that be the correct way to do this? I think that's what you are suggesting if I understand what you wrote correctly.
 
Upvote 0
Most of the app is based on a gridview so I modeled my app on the GridView sample. So the callback for the gridview is contained in the main activity. In one of the grids I used a LinearLayout consisting of one TextView and 3 ImageViews which are meant to act as buttons for selecting new views. This is done in the AdpaterView class for the gridview.

I was trying to find the resource within the gridview's callback function since I assumed the view would be valid when it was called - but nesting the LinearLayout callback within the gridview callback sounds messy - I'm not sure if it would even work.

I'm not sure if the correct solution would be to do this within the AdpaterView class or create a new class for the LinearLayout and implement the callback in there.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones