android - How to get HTML ImageGetter to work properly -


i have implemented imagegetter within html.fromhtml method reading following posts: html.fromhtml problem, , html.imagegetter. here code imagegetter:

if (mitem != null) {         ((textview) rootview.findviewbyid(r.id.exercise_detail))                 .settext(html.fromhtml(mitem.description, new imagegetter(){                   @override public drawable getdrawable(string source) {                       drawable drawfrompath;                       int path =                             exercisedetailfragment.this.getresources().getidentifier(source, "drawable",                                     "com.package.chaitanyavarier.mytrainer2go");                       drawfrompath = (drawable) exercisedetailfragment.this.getresources().getdrawable(path);                       drawfrompath.setbounds(0, 0, drawfrompath.getintrinsicwidth(),                          drawfrompath.getintrinsicheight());                       return drawfrompath;                    }                 }, null));      } 

here html within string called description (inside activity file) becomes path:

<img src =\"file:///android_asset/img/situp1.png\"> 

i have put image named situp1.png inside folder named img inside assets folder.

the problem path within html not getting parsed properly, , app crashes when try load item containing image. know fact string within img tag getting recognized, , have verified through debugging.

the way solved change

<img src =\"file:///android_asset/img/situp1.png\">  

to

<img src=\"situp1\">  

as in resource folder , hence drawable.

i had change

exercisedetailfragment.this.getresources().getidentifier(source, "drawable", "com.package.chaitanyavarier.mytrainer2go");  

to

exercisedetailfragment.this.getresources().getidentifier(source, "drawable", "com.chaitanyavarier.mytrainer2go"); 

a rather silly problem had, had understand code little better.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -