An example of click color change of listview implemented by Android

An example of click color change of listview implemented by Android

I made a music player, in which the listview is used to display the song list. When I click a song, I want the background color of the item where the song is located to change to highlight the selected song.

First of all, I think of writing in itemclicklistener, as follows:

When an item is selected, the color will be changed. When another item is selected, the previous item will be restored to the previous color. But I found a problem, that is, when I select an item, the color of more than one item will change. Sliding down, I found that the colors of several other items have also been changed. Does the view arg1 parameter in the onItemClick method change with the content displayed on the screen? I dare not talk nonsense, but this method won't work.

Later, it was found that there was a very simple method. Android had thought that we would need this function and directly provided a method to realize this function.

Add such a method directly to the listview. Perfect to achieve this function.

The above is the realization of Android listview click color change. There are many articles on Android Development on this site. I hope you can search and consult. Thank you for reading. I hope it can help you. Thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>