java - Updating collection-based Widget RemoteViews after AsyncTask callback -
i'm in situation elements of widget's listview reliant on content fetched on network via asynctask. code getviewat in remoteviewsfactory implementation follows:
val prerendered = remoteviews(context.packagename, r.layout.list_item_layout) myasynctask(prerendered).execute() return prerendered
and asynctask defined inner class
private inner class myasynctask(val remoteviews: remoteviews) : asynctask<void, void, bitmap>() { override fun doinbackground(vararg nothing: void): bitmap = <fetch image internet synchronously> override fun onpostexecute(result: bitmap) = remoteviews.setimageviewbitmap(r.id.imageview, result) }
my basic train of thought should perform rendering of default layout remoteviews , return inserted list, allow network operations take place in background. make modifications in onpostexecute method of asynctask on same instance of remoteviews, believe should in theory result in actual list element being updated. however, despite onpostexecute being run , view being populated initial layout, image never set. have thoughts on how achieve this?
afterthought: i've tried using textview , setting static text in asynctask , not work.
consider using listview
, arrayadapter
. here link 1 tutorial on subject.
the idea have background task update backing data rather view directly. backing data collection of items representing data each item in list. asynctask
it's thing , update item in collection. call notifydatasetchanged()
on arrayadapter
update listview
.
Comments
Post a Comment