I would suggest you to create Task
class, which would implement Runnable
and have a method getCurrentProgress()
, which would return progress of current task and a method cancel()
to cancel itself (canceling can be done in any desired way, by raising a flag or any other way). Then you can start a task using ordinary thread (or use AsyncTask, or one of Executors
) and add your Task
s to adapter as an item, and then you can display appropriate Views by using
Task task = getItem(position);
progressBar.setProgress(task.getCurrentProgress());
in your getView()
method of adapter.
Then when you need to update progress you just need to update progress inside Task
and call adapter.notifyDataSetChange()
on the UI thread. What you also need to do is to ensure that your new progress in Task
instance would be visible from other threads, for this I would suggest you using AtomicInteger
as progress indicator (because every AtomicInteger.get()
returns the latest value).