
I know how to create a list with View like the ones shown above. I am attempting to create a downloader and there will be multiple threads downloading at the same time.
These Threads needs to use the setProgress(..) of the ProgressBar. However, I do not know how I can refer to these progress bars once they have been created using an adapter. And, by extension, the cancel buttons so that I can add listeners to it.
Please help me with this
I would suggest you to create
Taskclass, which would implementRunnableand have a methodgetCurrentProgress(), which would return progress of current task and a methodcancel()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 ofExecutors) and add yourTasks to adapter as an item, and then you can display appropriate Views by usingin your
getView()method of adapter.Then when you need to update progress you just need to update progress inside
Taskand calladapter.notifyDataSetChange()on the UI thread. What you also need to do is to ensure that your new progress inTaskinstance would be visible from other threads, for this I would suggest you usingAtomicIntegeras progress indicator (because everyAtomicInteger.get()returns the latest value).