sub item click listner in android custom gridview implementation -


i have grid view custom adapter implementation. on touching grid view item, entire item selected. want perform different action on selecting different sub item in grid view.

in below example, have 2 images , 1 textview in item. want perform different action on touching textview, image view.

is possible in android ?

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listrow" android:layout_width="fill_parent" android:layout_height="66dp" android:background="@drawable/grid_color_selector" android:descendantfocusability="blocksdescendants" android:focusable="false" android:focusableintouchmode="false" android:gravity="fill_horizontal" >  <linearlayout     android:layout_width="fill_parent"     android:layout_height="match_parent"     android:focusable="false"     android:focusableintouchmode="false"     android:orientation="horizontal" >      <imageview         android:id="@+id/thumbimage"         android:layout_width="50dp"         android:layout_height="50dp"         android:layout_margin="4dp"         android:layout_weight="1"         android:clickable="false"         android:focusable="false"         android:focusableintouchmode="false"         android:scaletype="fitxy"         android:src="@drawable/icon" />      <textview         android:id="@+id/txttitle"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_marginleft="5dp"         android:layout_margintop="10dp"         android:layout_weight="44"         android:clickable="false"         android:focusable="false"         android:focusableintouchmode="false"         android:text="english channels"         android:textcolor="@color/black"         android:textsize="16sp" />      <imageview         android:id="@+id/share"         android:layout_width="50dp"         android:layout_height="50dp"         android:layout_margin="4dp"         android:layout_weight="1"         android:clickable="false"         android:focusable="false"         android:focusableintouchmode="false"         android:scaletype="fitxy"         android:src="@drawable/share" />  </linearlayout> 

the custom gridview implementation

public class gridviewadapterimpl extends arrayadapter < string > { private final activity context; private final string[] data; private int resource;  public gridviewadapterimpl(activity context, int resource, string[] filenames) {     super(context, resource, filenames);     this.resource = resource;     this.context = context;     this.data = filenames; }  @override public view getview(int position, view convertview, viewgroup parent) {     view row = convertview;     viewholder holder = null;      if (row == null) {         layoutinflater inflater = ((activity) context).getlayoutinflater();         row = inflater.inflate(resource, parent, false);         holder = new viewholder();         holder.imagetitle = (textview) row.findviewbyid(r.id.txttitle);         row.settag(holder);     } else {         holder = (viewholder) row.gettag();     }      holder.imagetitle.settext(data[position]);     return row; }  static class viewholder {     textview imagetitle; } 

the gridview call

gridview gridview = (gridview) findviewbyid(r.id.gridview); 

gridviewadapterimpl customgridadapter = new gridviewadapterimpl(this, r.layout.row_list_videos, this.getvideofiles()); gridview.setadapter(customgridadapter);

gridview.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview parent, view v, int position, long id) { < perform action > } });

just add imageview component viewholder, , implement listeners, see this:

public class gridviewadapterimpl extends arrayadapter < string > { private final activity context; private final string[] data; private int resource;  public gridviewadapterimpl(activity context, int resource, string[] filenames) {     super(context, resource, filenames);     this.resource = resource;     this.context = context;     this.data = filenames; }  @override public view getview(int position, view convertview, viewgroup parent) {     view row = convertview;     viewholder holder = null;      if (row == null) {         layoutinflater inflater = ((activity) context).getlayoutinflater();         row = inflater.inflate(resource, parent, false);         holder = new viewholder();         holder.imagetitle = (textview) row.findviewbyid(r.id.txttitle);         holder.imvshare = (imageview) row.findviewbyid(r.id.share)         // set onclicklistener               holder.imagetitle.setonclicklistener(plsntitleclicklistener);         holder.imvshare.setonclicklistener(plsnshareclicklistener);         row.settag(holder);     } else {         holder = (viewholder) row.gettag();     }      holder.imagetitle.settext(data[position]);     return row; }  private onclicklistener plsntitleclicklistener = new onclicklistener() {     @override     public void onclick(view v) {         // todo implement logic here     } };  private onclicklistener plsnshareclicklistener = new onclicklistener() {     @override     public void onclick(view v) {         // todo implement logic here     } };  static class viewholder {     textview imagetitle;     imageview imvshare; } 

Comments