Listview developed by Android realizes local refresh of item

Most of the programmers are familiar with the ListView refresh mechanism in Android, modify or add the data source in adapter, then call notifyDataSetChanged () to refresh ListView. In this mode, we will let the control display different contents according to different data sources in getview. This mode is the most common refresh mode. When we slide the listview back and forth, we call the getview method of the adapter, and then listview draws the view returned by the adapter. In this mode, the display content or status of the view is recorded in the data source in the adapter. The update frequency of listview is not frequent, and it is updated with the change of the data source.

However, there is a download module when making a company project. Because several data may be downloaded at the same time, the listview is used to display all the contents being downloaded. Because the download progress needs to be updated in real time, you keep calling notifydatesetchanged to refresh the data. This will constantly redraw the interface of the whole listview, and the performance overhead is very large. Moreover, if each item has a picture, the picture of each item needs to be reloaded. Even if the picture is cached in memory, refreshing the picture will flash. Constant refreshing will cause the picture of each item to flash continuously, and the experience is not good at all.

So is there a solution to the above problem? Of course. We can locally update an item without affecting other items that have not been modified. So how to achieve it? Let's look at the code below.

This function mainly obtains the view displayed by the data of itemindex according to the passed in itemindex. Itemindex is the location of the data to be modified in the list set. For example, I have updated the download progress here, sent a broadcast, and received it here. It is necessary to modify the progress bar of the downloaded content. The broadcast receiver can write as follows:

Let's look at the specific code of the adapter:

The above content is all about the listview developed by Android to realize the local refresh of item. I hope it will be useful to you. For more information about the local refresh of listview, please log in to the official website of programming tips. Thank you!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>