android - Gridview click not working inside the Custom Listview -


i'm using gridview inside listview, have focusable problem.

i have set width of gridview, fill items of gridview, on left space of gridview (which blank) means items not fill of gridview in listview. if click on it, not perform listitem click

enter image description here

as given in image, want perform listview item click if clicked anywhere in list item. want listitem click.

but when click on listview item, is, gridview listitem click not working...

public class history extends activity {      string name, id, description, count, total;      arraylist<string> tag_id = new arraylist<string>();     arraylist<string> tag_coffeeshop_name = new arraylist<string>();     arraylist<string> tag_count = new arraylist<string>();     arraylist<string> tag_total = new arraylist<string>();      context context;     jsonarray coffeeuser = null;      public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.listlayout);         listview listview = (listview) findviewbyid(r.id.listnew);         listview.setadapter(new mycustomadapter());         listview.settextfilterenabled(true);         listview.setonitemclicklistener(new adapterview.onitemclicklistener()         {             public void onitemclick(adapterview<?> paramanonymousadapterview, view paramanonymousview, int paramanonymousint, long paramanonymouslong)             {                 intent intent = new intent();                 intent.putextra("coffeeshopid", ((textview)paramanonymousview.findviewbyid(r.id.hlcoffeeshopid)).gettext() );                 intent.setclass(getparent(), stamps.class);                 historystack hisstack = (historystack) getparent();                 hisstack.push("stamps", intent);             }         });     }      class mycustomadapter extends baseadapter {         context ctx;          public mycustomadapter() {             // creating json parser instance             jsonparser jparser = new jsonparser();             sharedpreferences prfs = getsharedpreferences("guid_file_name", context.mode_private);                 jsonobject json = jparser.methodhistory("http://api.com");             try {                 // getting array of employee                 coffeeuser = json.getjsonarray("coffeeuser");                  // looping of list                 (int = 0; < coffeeuser.length(); i++) {                     jsonobject c = coffeeuser.getjsonobject(i);                      // storing each json item in variable                     id = c.getstring("cs_id");                     name = c.getstring("shopname");                     count = c.getstring("totalstamps");                     total = c.getstring("threshholdcount");                      // adding values array                     if (name != "null") {                         tag_coffeeshop_name.add(name);                         tag_id.add(id);                         tag_total.add(total);                         tag_count.add(count);                     }                 }             }             catch (jsonexception e) {                 e.printstacktrace();             }         }          @override         public int getcount() {             return tag_coffeeshop_name.size();         }          @override         public object getitem(int paramint) {             return tag_coffeeshop_name.get(paramint);         }          @override         public long getitemid(int paramint) {             return paramint;         }          public class mycustomholder {             public gridview localgrid;             public textview coffeeshopname,coffeeshopsdescription,coffeeshopid;         }          @override         public view getview(int paramint, view paramview,viewgroup paramviewgroup) {             view localview = paramview;             mycustomholder holder = null;             if (localview == null) {                 layoutinflater inflater = (layoutinflater) history.this.getsystemservice(context.layout_inflater_service);                 localview = inflater.inflate(r.layout.historylist, null);                 holder = new mycustomholder();                 holder.coffeeshopname = (textview) localview.findviewbyid(r.id.hlcoffeeshopname);                 holder.coffeeshopid = (textview) localview.findviewbyid(r.id.hlcoffeeshopid);                 holder.localgrid = (gridview) localview.findviewbyid(r.id.gridviewdistorylist);                 localview.settag(holder);             }             else {                 holder = (mycustomholder) localview.gettag();             }             holder.coffeeshopname.settext(tag_coffeeshop_name.get(paramint));             holder.coffeeshopid.settext(tag_id.get(paramint));             holder.localgrid.setadapter(new gridadaptera(history.this, tag_total.get(paramint), tag_count.get(paramint)));             holder.localgrid.setfocusable(false);             holder.localgrid.setfocusableintouchmode(false);             holder.coffeeshopname.setfocusable(false);             holder.coffeeshopname.setfocusableintouchmode(false);             localview.setonclicklistener(new view.onclicklistener() {                  @override                 public void onclick(view v) {                     // todo auto-generated method stub                      intent intent = new intent();                         intent.putextra("coffeeshopid", ((textview)v.findviewbyid(r.id.hlcoffeeshopid)).gettext() );                           intent.setclass(getparent(), stamps.class);                           historystack hisstack = (historystack) getparent();                           hisstack.push("stamps", intent);                 }             });              return localview;         }     }      public class gridadaptera extends baseadapter {          private context context;         string total,count;          public gridadaptera(context context) {             this.context = context;         }          public gridadaptera(context context, string total, string count) {             // todo auto-generated constructor stub             this.context = context;             this.total = total;             this.count = count;         }          public boolean areallitemsenabled()         {             return false;         }          public boolean isenabled(int position)         {             return false;         }          public view getview(int position, view convertview, viewgroup parent) {              layoutinflater inflater = (layoutinflater) context                 .getsystemservice(context.layout_inflater_service);              view gridview;              if (convertview == null) {                 gridview = new view(context);                 gridview = inflater.inflate(r.layout.customgrid_row, null);                 gridview.setfocusable(false);                 imageview imageview = (imageview) gridview.findviewbyid(r.id.grid_item_image);                 imageview.setfocusable(false);                 int = 0;                 if(count!="null")                 = integer.parseint(count);                  if (position<i ) {                     //imageview.setimageresource(r.drawable.ii);                     //    textview.settext(gridlist[position]);                 }                 else {                     imageview.setimageresource(r.drawable.changedcup);                     // textview.settext("");                 }             }             else {                 gridview = (view) convertview;             }             /*gridview.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 intent intent = new intent();                 intent.putextra("coffeeshopid", ((textview)v.findviewbyid(r.id.hlcoffeeshopid)).gettext() );                 intent.setclass(getparent(), stamps.class);                 historystack hisstack = (historystack) getparent();                 hisstack.push("stamps", intent);    }             });*/              return gridview;         }          @override         public int getcount() {             int j=0;             if(total!="null"){             j = integer.parseint(total);             }             return j;         }          @override         public object getitem(int position) {             return null;         }          @override         public long getitemid(int position) {             return 0;         }     } } 

historylist

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:background="@drawable/list_selector"     android:orientation="horizontal"     android:padding="5dip" >      <linearlayout         android:id="@+id/thumbnail"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_marginright="5dip"         android:background="@drawable/image_bg"         android:padding="3dip" >          <imageview             android:id="@+id/list_image"             android:layout_width="50dip"             android:layout_height="50dip"             android:src="@drawable/rcup" />     </linearlayout>      <!-- hlcoffeeshopname of song -->      <textview         android:id="@+id/hlcoffeeshopname"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_aligntop="@+id/thumbnail"         android:layout_torightof="@+id/thumbnail"         android:text="rihanna love way lie"         android:textcolor="#040404"         android:textsize="20dip"         android:textstyle="bold"         android:typeface="sans" />      <textview        android:id="@+id/hlcoffeeshopid"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:visibility="gone"     />      <gridview         xmlns:android="http://schemas.android.com/apk/res/android"         android:id="@+id/gridviewdistorylist"         android:layout_width="wrap_content"         android:layout_height="40dp"         android:layout_below="@+id/hlcoffeeshopname"         android:layout_torightof="@+id/thumbnail"         android:columnwidth="20dp"         android:background="@null"         android:descendantfocusability="blocksdescendants"         android:focusable="false"         android:focusableintouchmode="false"         android:numcolumns="10"         android:stretchmode="none" >     </gridview> </relativelayout> 

new getview

@override     public view getview(int paramint,                         view paramview,                         viewgroup paramviewgroup) {         view localview = paramview;         mycustomholder holder = null;         if (localview == null) {             layoutinflater inflater = (layoutinflater) copyofhistory.this.getsystemservice(context.layout_inflater_service);             localview = inflater.inflate(r.layout.copyhistorylist, null);             holder = new mycustomholder();             holder.coffeeshopname = (textview) localview.findviewbyid(r.id.hlcoffeeshopname);             holder.coffeeshopid = (textview) localview.findviewbyid(r.id.hlcoffeeshopid);             localview.settag(holder);         }         else {             holder = (mycustomholder) localview.gettag();         }         holder.coffeeshopname.settext(tag_coffeeshop_name.get(paramint));         holder.coffeeshopid.settext(tag_id.get(paramint));          int looplimit = integer.parseint(tag_total.get(paramint));         (int = 0; < looplimit; i++) {             log.e("loop", string.valueof(looplimit));             imageview imageview = new imageview(copyofhistory.this);             if (i < integer.parseint(tag_count.get(paramint))) {                 imageview.setimagedrawable(getresources().getdrawable(r.drawable.ii));             } else {                 imageview.setimagedrawable(getresources().getdrawable(r.drawable.iii));             }             relativelayout layout = (relativelayout) localview.findviewbyid(r.id.hlrlayout);             relativelayout.layoutparams params = new relativelayout.layoutparams(30,30);             params.setmargins(i*40, 0, 0, 0);             imageview.setlayoutparams(params);             layout.addview(imageview);             //holder.relativelayout = new relativelayout();         }          holder.coffeeshopname.setfocusable(false);         holder.coffeeshopname.setfocusableintouchmode(false);         localview.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 intent intent = new intent();                 intent.putextra("coffeeshopid", ((textview) v                         .findviewbyid(r.id.hlcoffeeshopid)).gettext());                 intent.setclass(getparent(), stamps.class);                 historystack hisstack = (historystack) getparent();                 hisstack.push("stamps", intent);             }         });          return localview;     } 

you might have solved it, have solution may someone.

use android:descendantfocusability="beforedescendants" in root layout of list_cell xml.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -