android - GridView not displaying if called not from button -
i'm new java, android etc. have problem not able figure out.
i have gridview
populated imageadapter
based on universalimageloader
. when click button launch method,
public void buttonsearch(view view) { imagesearch(); }
gridview
display images. when call directly.
imagesearch("somestring");
it's showing nothing @ all. "debug" messages can see imageadapter
working. , when click button, gridview
starts filling content.
private void imagesearch(string... params) throws clientprotocolexception, jsonexception, ioexception, interruptedexception, executionexception { edittext wordimage = (edittext) findviewbyid(r.id.wordimage); string previos = null; string wordtotr = null; string strwordtos = null; if ( params.length != 0 ) { previos = params[0]; } if ( previos != null) { strwordtos = previos; wordimage.settext(strwordtos); } strwordtos = wordimage.gettext().tostring().replaceall(" ", "%20"); parsejsonimages geturls = new parsejsonimages(); geturls.execute(strwordtos); urlsp = geturls.get(); list<string> urls = new arraylist<string>(); urls = new arraylist<string>(urlsp.values()); directurls = new arraylist<string>(urlsp.keyset()); int j = 0; while (urls.size() > j) { urls.set(j, "http://someaddress:" + urls.get(j)); j++; } gridview gridview = (gridview) findviewbyid(r.id.gridviewimages); integer gwight = gridview.getwidth(); integer ghight = gridview.getheight(); imageadapter images = new imageadapter(this, urls, ghight, gwight); gridview.setadapter(images); gridview.setselected(true); gridview.setonitemclicklistener(new onitemclicklistener() { public void setalphatoimagebypos(integer pos, integer alpha) { gridview gridview = (gridview) findviewbyid(r.id.gridviewimages); imageview imgrecoil = (imageview) (gridview .getchildat(pos)); imgrecoil.setalpha(alpha); } public void onitemclick(adapterview parent, view v, int position, long id) { if (strimgtag > -1) { setalphatoimagebypos(strimgtag, 255); strimgtag = position; setalphatoimagebypos(strimgtag, 128); } });
edit: ok problem solved explaining later
ok, tried dimensions before gridview
drawn. in oncreate()
when called method launch code after gridview
drawn.
public void waiter() { final gridview gridview1 = (gridview) findviewbyid(r.id.gridviewimages); gridview1.getviewtreeobserver().addongloballayoutlistener(new viewtreeobserver.ongloballayoutlistener() { @override public void ongloballayout() { gridview1.getviewtreeobserver().removeglobalonlayoutlistener(this); gwight = gridview1.getwidth(); ghight = gridview1.getheight(); try { imagesearch(wordfromprev); } catch (clientprotocolexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (executionexception e) { // todo auto-generated catch block e.printstacktrace(); } } }); }
Comments
Post a Comment