tags:

views:

37

answers:

2

Hi,

My adapter contain the following Views:

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

This Is how I implement onItemClick :

gridView.setOnItemClickListener(new OnItemClickListener() {  
             public void onItemClick(AdapterView<?> parent, View v, int position, long id) {       
            }  
         });

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

Thanks

+1  A: 

The second parameter to onItemClick, View v is a reference to the view that was clicked. You can compare this to your views to see which one it was.

Mayra
Hi,The view will contained the ViewHolder object but how can I know which view was select in the ViewHolder ? ( ImageView p_Image or TextView p_Name or TextView p_Price or TextView p_Psave)Any code example will be helpfulThanks
chen
Oh, I see, you are listing for click events on the gridView, not on the individual items. In that case, unfortunately there isn't an easy way to tell which subcomponent was clicked. If you care about that, then rather than listening for clicks on grid view items, you should add a click listener to each individual view. Remember though, that people often have a hard time clicking on small areas. You might be better off with a design where the click on the grid item and then get more options, or are taken to a details screen where they have more choices.
Mayra
A: 

Thanks for the help

rcy