Highlight ListView selected row

前端 未结 12 1503
情歌与酒
情歌与酒 2020-11-27 16:04

I have a list of albums (several hundred). When I touch the selected album I want to offer the user a choice of playing the whole album, or moving to its track ListView. No

12条回答
  •  日久生厌
    2020-11-27 16:10

    I solved this by extending the ListView and overriding the getView() method. I kept an internal identifier for the "selected" state and changed the background of the item according to it, like this:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    View currView = super.getView(position, convertView, parent);
    StateListItem currItem = getItem(position);
    if (currItem.isItemSelected) {
        currView.setBackgroundColor(Color.RED);
    } else {
        currView.setBackgroundColor(Color.BLACK);
    }
    return currView;
    }  
    

    I have an example program on my blog post: http://udinic.wordpress.com/2011/07/01/selectablelistview-make-selection-work/

提交回复
热议问题