Android 如何让HTML ImageGetter正常工作

Android 如何让HTML ImageGetter正常工作,android,string,image,path,html-parsing,Android,String,Image,Path,Html Parsing,通过阅读以下文章,我在Html.fromHtml方法中实现了ImageGetter:,和。 以下是ImageGetter的代码: if (mItem != null) { ((TextView) rootView.findViewById(R.id.exercise_detail)) .setText(Html.fromHtml(mItem.description, new ImageGetter(){ @Ove

通过阅读以下文章,我在Html.fromHtml方法中实现了ImageGetter:,和。 以下是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));

    }
以下是名为description(在另一个活动文件中)的字符串中的HTML,该字符串将成为路径:

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

我把一个名为situp1.png的图像放在一个名为img的文件夹中,该文件夹位于assets文件夹中


问题是我的HTML中的路径没有得到正确解析,当我尝试加载包含图像的项目时,应用程序崩溃。我知道img标记中的字符串正在被识别,我已经通过调试验证了这一点。

我解决这个问题的方法是改变

<img src =\"file:///android_asset/img/situp1.png\"> 
ExerciseDetailFragment.this.getResources().getIdentifier(source, "drawable", "com.package.ChaitanyaVarier.mytrainer2go"); 

我遇到了一个相当愚蠢的问题,只是需要更好地理解代码

ExerciseDetailFragment.this.getResources().getIdentifier(source, "drawable", "com.package.ChaitanyaVarier.mytrainer2go"); 
ExerciseDetailFragment.this.getResources().getIdentifier(source, "drawable", "com.ChaitanyaVarier.mytrainer2go");