Download multiple files with a progress bar in ListView Android

后端 未结 2 505
梦毁少年i
梦毁少年i 2020-11-28 19:50

I want to create a ListView that allows the user to download many files and show a progress bar status in each ListView item. It looks like this:

2条回答
  •  青春惊慌失措
    2020-11-28 20:16

    IMO - 4 things you would want to implement:

    • Listener/Wrapper for HttpClient.Get.Exec() - so you know how many bytes received on each write()

      Broadcast/receive for listener that u mention may actually be redundant

      Async HttpClient - nonblocking is a MUST

      Pooling/Queueing for requests

    for the Listener you can see the observer pattern and switch the 'upload' to down.

    since you already have an observer pattern you should be able to adapt it to your architecture requirement. When the listener callsBack on the I/O within the get.exec(), you just need and interface that allows you to callback on the activity/fragment that has the UI and the adapter for your list so that it can be notified of the change in count-bytes-read-on-http-GET. The i/o callback will have to either reference the correct list entry in the adapter or provide some other ID so that it can be tied back to a particular GET. I've used handlers and the args in obtainMessageHandler() for that purpose. When the Handler provide and ID to a specific GET... then the listener will have a reference to the same ID or arg when it makes its callback to count i/o bytes.

    for items 3 and 4, there is alot of stuff out there. Native Apache httpclients have pools/queues. Android volley offers that as well. More details here on the mechanics of handlers and 'obtainMessage' for the callbacks.

提交回复
热议问题