android - Want to show text and image from url in a textview no available examples are working -


i know question have lots of answer nothing seems work me don't know wrong please have on below code. had used lots of examples nothing work me.

     txt = (textview) findviewbyid(r.id.txt);      string html = "hello " +             "<img src='http://www.gravatar.com/avatar/" +             "f9dd8b16d54f483f22c0b7a7e3d840f9?s=32&d=identicon&r=pg'/>" +             " test " +             "<img src='http://www.gravatar.com/avatar/a9317e7f0a78bb10a980cadd9dd035c9?s=32&d=identicon&r=pg'/>";     spannedvalue = html.fromhtml(html,getimagehtml(),null);     txt.settext(spannedvalue); 

this drawer method.

    @override     public drawable getdrawable(string source) {     levellistdrawable d = new levellistdrawable();     drawable empty =      context.getresources().getdrawable(r.drawable.ic_launcher);     d.addlevel(0, 0, empty);     d.setbounds(0, 0, empty.getintrinsicwidth(),      empty.getintrinsicheight());      new loadimage().execute(source, d);       return null; } 

this image loader class checked hardcoded url also.

     class loadimage extends asynctask<object, void, bitmap> {      private levellistdrawable mdrawable;      @override     protected bitmap doinbackground(object... params) {         string source = (string) params[0];         mdrawable = (levellistdrawable) params[1];         log.d(tag, "doinbackground " + source);         try {              url url = new url("https://www.gochatin.com/cdn/emoji/v1.0/assets/png/master/emoji_u1f601.png ");                  log.d("url",url.tostring());             return            bitmapfactory.decodestream(url.openconnection().getinputstream());              /*inputstream = new url(source).openstream();             return bitmapfactory.decodestream(is);*/         } catch (filenotfoundexception e) {             e.printstacktrace();         } catch (malformedurlexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }         return null;     }      @override     protected void onpostexecute(bitmap bitmap) {         log.d(tag, "onpostexecute drawable " + mdrawable);         log.d(tag, "onpostexecute bitmap " + bitmap);         if (bitmap != null) {             log.d(tag, "onpostexecuteafter" + bitmap);             bitmapdrawable d = new bitmapdrawable(bitmap);             mdrawable.addlevel(1, 1, d);             mdrawable.setbounds(0, 0, bitmap.getwidth(),              bitmap.getheight());             mdrawable.setlevel(1);             // don't know yet better way refresh textview             // mtv.invalidate() doesn't work expected             charsequence t = txtmsg.gettext();             txtmsg.settext(t);         }     } } 

finally fixed issue .this how fixed.

     txtmsg.settext(html.fromhtml(m.getmessage(),new imagegetter(), null)); 

and below imagegetter method.

     public class imagegetter implements html.imagegetter {      public drawable getdrawable(string source) {         int id;         log.d("source",source);           bitmap bitmap = null;         try {             bitmap = new loadimage().execute(source).get();         } catch (interruptedexception e) {             e.printstacktrace();         } catch (executionexception e) {             e.printstacktrace();         }         drawable d =new bitmapdrawable(getresources(),bitmap);         d.setbounds(0,0,d.getintrinsicwidth(),d.getintrinsicheight());         return d;     }  } 

this imageloader class

     class loadimage extends asynctask<string, void, bitmap> {      private levellistdrawable mdrawable;      @override     protected bitmap doinbackground(string... params) {          try {              url=new url(params[0]);            // url = new url("http://www.gravatar.com/avatar/a9317e7f0a78bb10a980cadd9dd035c9?s=32&d=identicon&r=pg");             bitmap = bitmapfactory.decodestream(url.openconnection().getinputstream());            /* runonuithread(new runnable() {                 @override                 public void run() {                    // tasteimf.setimagebitmap(bitmap);                     textviewt.settext(html.fromhtml(html,new imagegetter(), null));                 }             });*/             log.d("image",bitmap.tostring());            // bitmap = picasso.with(mainactivity.this).load("http://www.gravatar.com/avatar/a9317e7f0a78bb10a980cadd9dd035c9?s=32&d=identicon&r=pg").get();             log.d("bitmap",bitmap.tostring());         } catch (ioexception e) {             e.printstacktrace();         }         return bitmap;     }      @override     protected void onpostexecute(bitmap bitmap) {         log.d(tag, "onpostexecute drawable " + mdrawable);         log.d(tag, "onpostexecute bitmap " + bitmap);         if (bitmap != null) {             log.d(tag, "onpostexecuteafter" + bitmap);            // mymethod(bitmap);             charsequence charsequence = textviewt.gettext();             textviewt.settext(charsequence);          }      } } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -