android - Get the Text of clicked item in gridView -


i have gridview in every cell contains imageview , textview. when user clicks on item, want take text of textview in position user clicked. tried code below, every time take first element.

grid.setonitemclicklistener(new adapterview.onitemclicklistener() {      public void onitemclick(adapterview<?> parent, view v, int position, long id) {          viewgroup gridchild = (viewgroup) grid.getchildat(position);         int childsize = gridchild.getchildcount();          for(int k = 0; k < childsize; k++) {            if(gridchild.getchildat(k) instanceof textview ){                   textview temp = (textview) findviewbyid(gridchild.getchildat(k).getid());                   stationid = temp.gettext().tostring();                   log.i("stationid", stationid);             }         } 

use

@override     public view getview(final int position, view convertview, viewgroup parent) {         view rowview = convertview;         rowview = inflater.inflate(r.layout.gridview_item, null);         textview tw1 = (textview) rowview.findviewbyid(r.id.textview); imageview im = (imageview) rowview.findviewbyid(r.id.imgaeview);          rowview.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) { string gettext=tw1.gettext();              }          return rowview;     } 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -