Android ListView row color

后端 未结 2 829
北海茫月
北海茫月 2021-01-26 09:48

I\'m trying to change the row color of my listView in customAdapter. There\'s an array of integer that include 0 and 1, I\'m trying to read from the array and change the color o

2条回答
  •  别那么骄傲
    2021-01-26 10:25

    Fast solution (not very nice code, but works):

    @Override
    public int getItem(int position){
      return test.get(position);
    }
    
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    
      int color0 = ....
      int color1 = ....
      int colorDefault = ...
    
      switch (test.get(position)) {
         case 0:
                 convretview.setBackgroundColor(color0);
                 break;
         case 1:
                convretview.setBackgroundColor(color1);
                break;
         default:
               convretview.setBackgroundColor(colorDefault); 
      }
      ...
    }
    

提交回复
热议问题