android listview alternate row color BUT with default cursor selection

后端 未结 1 1562
走了就别回头了
走了就别回头了 2021-01-06 16:11

i have been all over the web, stackoverflow included and just can\'t seem to get a clear complete way to

I want to create a ListView that

1) has alternating

1条回答
  •  囚心锁ツ
    2021-01-06 16:53

    A workaround is to use 2 selectors. From your adapter, instead of setting 2 colors, you set 2 selectors.

    if (position % 2 == 0) {
      view.setBackgroundResource(R.drawable.selector_1);
    } else {
      view.setBackgroundResource(R.drawable.selector_2);
    }
    

    selector_1 is defined in selector_1.xml like this:

    
    
    
    
    
    
    

    selector_2 is defined in selector_2.xml like this:

    
    
    
    
    
    
    

    So that, you have a bi-color listview and a third color/shape/whatever-you-want for selected item.

    0 讨论(0)
提交回复
热议问题