简体   繁体   中英

Change background of single ListView item

I would like to have a listview where whenever I click on a list item that items background color and no others is changed. My problem is that when I scroll down the list after clicking on an item or two, some of the items that were out of view from the screen have somehow also had their background color changed as well.

I have tried everything I can think of and haven't found anything that has helped me online, so any help at all is greatly appreciated. Here is what I have got at its most basic:

protected void onListItemClick(ListView l, View v, int position, long id) {

    v.setBackgroundColor(Color.WHITE);
}

对ListView上的行使用自定义选择器,请参阅本教程

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM