File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes How to retrieve the right view? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "How to retrieve the right view?" Watch "How to retrieve the right view?" New topic
Author

How to retrieve the right view?

chen young
Ranch Hand

Joined: Sep 09, 2005
Posts: 188
Hi,

My adapter contain the following Views:

private static class ViewHolder {
ImageView p_Image;
TextView p_Name;
TextView p_Price;
TextView p_Psave;
}

How can I know which view from the above 4 was actually pressed (while running OnItemClickListener via GridView)

Thanks
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

If you add a OnItemClickListener on your GridView you will not be able to listen to click events on the individual child components.

You should be able to get a reference to the child views of your parent AdapterView though. onItemClick callback is supplied instances of the parent AdapterView i.e. (GridView) and the view returned by getView() method of the adapter. I think, doing a findViewById() on the view object should give a handle on the individual child components.


[List of FAQs] | [Android FAQ] | [Samuh Varta]
chen young
Ranch Hand

Joined: Sep 09, 2005
Posts: 188
HI,

This Is how I implement onItemClick :



Could you be more specific regarding how should I call getView() ?

Thanks

Jarrek Smith
Greenhorn

Joined: Oct 18, 2010
Posts: 5
In get View you bind the layout element to the ViewHolder propertie.

for example : in your viewHolder you have
ImageView img1

in get view you bind the image of the layout to img1

for example : img1= (ImageView) convertView.findViewById(R.id.icon)

then you add an onclick listener in img1

img1.setOnClickListener(new OnClickListener() { ...

that should do the trick.
Setting an on click listener on the gridView isn't precise enought.
You have to set an on click Listener on the view contained in your grid view

chen young
Ranch Hand

Joined: Sep 09, 2005
Posts: 188
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to retrieve the right view?
 
Similar Threads
Add label at the top of view
put in LIST Sample Data to debug, also how view SQLITE DB Data from Eclipse IDE for debug purposes
retrieve value from edittext from ListView
How to use AttributeSet in constructor
how to add textview and imageview randomly in a grid view in android