I have a ListView whose rows are formatted by me. Each row has a combination of ImageView and TextView. I also implemented my own adapter and can draw every line.
Now I would like something like this -
- The user clicks on the ImageView (nowhere in the line, but only this ImageView should respond to clicks)
- I recognize the position of the row at which ImageView was clicked.
I tried many things for this and wanted my code to be as efficient as possible (in terms of redundancy). Currently, I can only capture the click event for this particular ImageView, but I cannot find out which row was clicked.
I have provided an attribute in Row XML, for example:
<ImageView android:id="@+id/user_image" android:padding="5dip" android:layout_height="60dip" android:layout_width="60dip" android:clickable="true" android:onClick="uImgClickHandler"/>
And in my code, I have a method like this:
public void uImgClickHandler(View v){ Log.d("IMG CLICKED", ""+v.getId()); LinearLayout parentRow = (LinearLayout)v.getParent(); }
I can get the parent line (maybe), but I'm not sure how to go any further from here. Can anybody help?
source share