android - Using an AsyncTask to download images into a ListView in an AppWidget -


i trying adapt pattern google i/o using asynctask download images network , place them listview items within appwidget. haven't found many resources on doing such thing, except this post.

the problem is, poster didn't have collection view, single item. when try follow pattern, whole appwidget updated single list item every time onpostexecute() runs, not need. if remove call updateappwidget() in onpostexecute(), views not updated, i'm guessing because of inter-process communication must occur. i'm not sure go here, can help?

here definition asynctask:

public thumbnailasynctask(remoteviews rv, int appwidgetid, appwidgetmanager appwidgetmanager) {     mtarget = rv;     this.widgetid = appwidgetid;     this.widgetmanager = appwidgetmanager;   }  @override protected bitmap doinbackground(string... params) {     string url = params[0];     return getbitmapfromurl(url); }  @override protected void onpostexecute(bitmap result) {     mtarget.setimageviewbitmap(r.id.thumbnail, result);     widgetmanager.updateappwidget(widgetid, mtarget); }  private bitmap getbitmapfromurl(string str) {     bitmap bmp = null;     httpurlconnection connection = null;      try     {         url url = new url(str);         connection = openconnectionwithtimeout(url);         bmp = bitmapfactory.decodestream(connection.getinputstream());     }     catch (ioexception e)     {         e.printstacktrace();     }         {         connection.disconnect();     }     return bmp; } } 

and getviewat() remoteviewsfactory:

public remoteviews getviewat(int position) {     remoteviews rv = new remoteviews(mcontext.getpackagename(), r.layout.list_item);     arraylist<resultdetails> mresults = mjsonparser.getresults();      if (mresults.get(position).hasheading())         rv.settextviewtext(r.id.title, mresults.get(position).getheading());     if (mresults.get(position).hasbody())         rv.settextviewtext(r.id.description, mresults.get(position).getbody(true));     if (mresults.get(position).hastimestamp())         rv.settextviewtext(r.id.date, mresults.get(position).gettimestamp(true));      bundle extras = new bundle();     extras.putstring(link_item, mresults.get(position).getexternalurl());     intent fillinintent = new intent();     fillinintent.putextras(extras);     rv.setonclickfillinintent(r.id.list_item, fillinintent);      if (mresults.get(position).hasthumbnailurl())     {         appwidgetmanager mgr = appwidgetmanager.getinstance(mcontext);         new thumbnailasynctask(rv, mappwidgetid, mgr).execute(mresults.get(position).getthumbnailurl());     }      return rv; } 

i believe need call appwidgetmanager.notifyappwidgetviewdatachanged() refresh collection views in appwidget


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 -

Function that returns a formatted array in VBA -