I have implemented an ImageGetter within an Html.fromHtml method by reading the following posts: Html.fromHtml problem, and Html.ImageGetter. Here is the code with the 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 is the HTML within a string called description (inside another activity file) that becomes the path:
<img src =\"file:///android_asset/img/situp1.png\">
I have put an image named situp1.png inside a folder named img which is inside the assets folder.
The problem is that the path within my HTML is not getting parsed properly, and the app crashes when I try to load the item containing the image. I know for a fact that the string within the img tag is getting recognized, and I have verified this through debugging.