Search code examples
androidandroid-listviewlistviewitem

ListViewItem add progressbar to selected item on click


I have created a listview, with custom adapter. When I click an item within the list view, I download data async.

My question is, how can I add a progress bar (indeterminate) to the selected ListViewItem. Note that they will be able to click multiple ListViewItems (obviously not the same one while its downloading), which means there could by x number of progress bars at any given time.

I have tried adding it by casting the view (2nd param) to a view group and using AddView, but to no avail. It seems the view is the ListView and not the item.


Solution

  • Your listview item xml should also have a progressbar with visibility set to gone. When you're about to start download (on onPreExecute() of your async task) set progressbar to visible. When done downloading, set it to gone again.