android - ImageButton not 'getting' bitmap -


i have following function to download image:

private class downloadimagetask extends asynctask<string, void, bitmap> {      private imagebutton bmimage;      public downloadimagetask(imagebutton bmimage) {         this.bmimage = bmimage;     }      protected void onpreexecute() {          log.wtf("imagetask","onpreexecute");         //mdialog = progressdialog.show(chartactivity.this,"please wait...", "retrieving data ...", true);     }      protected bitmap  doinbackground(string... urls) {          bitmap bitmap = null;         string error_message = null;          for(string url:urls){             httpurirequest request = new httpget(url.tostring());             httpclient httpclient = new defaulthttpclient();             try {                 httpresponse response = httpclient.execute(request);                 statusline statusline = response.getstatusline();                 int statuscode = statusline.getstatuscode();                 if (statuscode == 200) {                     httpentity entity = response.getentity();                     byte[] bytes = entityutils.tobytearray(entity);                     log.e("here",""+bytes.length);                     bitmap = bitmapfactory.decodebytearray(bytes, 0,bytes.length);                     thread.sleep(1000);                 }                 else                 {                     error_message="download failed, http response code "+ statuscode + " - " + statusline.getreasonphrase();                 }             } catch (exception er) {                 log.e("error",""+er);             }}         //image.setimagebitmap(bitmap);         return bitmap ;     }      /*  old 1 (doesn't work)     protected bitmap doinbackground(string... urls) {         string urldisplay = urls[0];         bitmap micon11 = null;         try {             inputstream in = new java.net.url(urldisplay).openstream();             micon11 = bitmapfactory.decodestream(in);         } catch (exception e) {             log.wtf("error", "image download error");             log.wtf("error", e.getmessage());             e.printstacktrace();         }         return micon11;     }*/      protected void onpostexecute(bitmap result) {         log.wtf("imagetask","onpostexecute");         log.wtf("imagetask, post execute",result.tostring());         //set image of imageview         bmimage.setimagebitmap(result);          android.view.viewgroup.layoutparams params = bmimage.getlayoutparams();         params.height = 50;         params.width = 50;         bmimage.setlayoutparams(params);          int width = bmimage.getwidth();         int height = bmimage.getheight();          log.wtf("width",string.valueof(width));         log.wtf("height",string.valueof(height));         layout.addview(bmimage); //appending element (with image)      } } 

and following code create element:

private void buildelement(final string friend_id, final string user_id, string name){      imagebutton element = (imagebutton) getlayoutinflater().inflate(r.layout.element_layout, something, false);      string img_value = "valid image link"          element.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                  focus();              }         });          new downloadimagetask(element).execute(img_value);  } 

and here element_layout.xml:

<imagebutton     xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     style="?android:attr/buttonstylesmall"     android:text="new button"     android:layout_width="30dp"     android:layout_height="30dp"     android:scaletype="fitxy"     android:layout_alignparenttop="true"/> 

the imagebutton gets created indeed but it's tiny grey square. idea on why? also, log.wtf("width",string.valueof(width)); log.wtf("height",string.valueof(height)); logs '0', '0'. thank much...


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -