Change background colour of current listview item in adapter getView method

前端 未结 7 1236
迷失自我
迷失自我 2020-12-03 19:20

I am building a custom adapter for a listview - I would like this adapter to give the listview alternating background colours.

boolean alternate = false;

@         


        
7条回答
  •  青春惊慌失措
    2020-12-03 19:42

    You can use this code:

     if (position % 2 == 0) {
                holder.image.setBackgroundResource(R.drawable.image1);
            } else {
               holder.image.setBackgroundResource(R.drawable.image2);
            }
    

提交回复
热议问题