I am trying to display images dynamically on a home screen widget. As RemoveViews offer a very limited set of methods to interact with the layout, I'm trying to use HTML to get 开发者_如何学JAVAthe same effect. 
Regular HTML displays ok (<u>,<b> etc) however I can't get images to display. Instead I get a little empty square appear in the TextView.
E.g.
s = "<b>Hello</b> <img src='world'/>";
ImageGetter imgGetter = new ImageGetter(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setTextViewText(R.id.textarea, Html.fromHtml(s, imgGetter, null));
The image getter looks like the following:
public class ImageGetter implements Html.ImageGetter
{
    Context c;
    public ImageGetter(Context c)
    {
        this.c = c;
    }
    public Drawable getDrawable(String source) {
        Drawable d = null;
        int resID = c.getResources().getIdentifier(source, "drawable", c.getPackageName());
        d = c.getApplicationContext().getResources().getDrawable(resID);
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
        return d;
    }
}
The code works fine if I am using a regular Activity. I suspect that this is a bug/undocumented feature of android when used with a AppWidgetProvider. I just want some confirmation.
I am trying to display images dynamically on a home screen widget.
Use ImageView. Update the app widget when you wish to change the image.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论