0

I'm having problem with an AsyncTask in my app. I load some dat in doInBackground(), and with that data (contains a link to download an image) I fill a ListView. My idea was to fill the ListView in onPostExecute(), but I can't because the adapter uses a Http connection to download the image and show it.

So, if I put the adapter in onPostExecute() Android tells me that I can't make a network connection in UI main thread. But if I did it doInBackground() it tells me that only the original thread that created a view hierarchy can touch it views.

Any suggestion?

Jon Zangitu
  • 957
  • 1
  • 15
  • 30
  • You can not update UI from other threads. You'd need to create a handler in the ui thread, call the handler from your AsyncTask.onPostExecute(). Then you can update the ui, from Handler.handleMessage(...) – Gaurav Arora Feb 18 '13 at 14:49
  • post your adapter and AsyncTask, You should likely be executing your AsyncTask from inside the Adapter, that way your loading will happen in the background. It's hard to tell without any code to look at though. – FoamyGuy Feb 18 '13 at 14:58
  • So, because I'm executing two http connections (one for getting the list elements, another one to get the image in each row of the list), I should use two AsyncTasks... Thank you FoamyGuy, probably this is the best approach. – Jon Zangitu Feb 18 '13 at 15:55

0 Answers0