title: ListView item background color
body: <p>I have a ListView in which every second item should have a different color (for example: white -> gray -> white ->gray  etc.), it seems to work initially but as soon as I start scrolling, the rendering of the backgroundcolor seems to fail: the other color is set randomly to the items, also when I scroll up again this happens to the items where the color was correct at the beginning. Can someone hint me why this is happening?</p>
  
  <p>I have tried this in the Adapter:</p>
  
  <pre><code>    if((position % 2) == 1) {
          layoutHolder.setBackgroundColor(getContext().getResources().getColor(R.color.light_green));
      }
  </code></pre>
  
  <p>and this in my ListFragment:</p>
  
  <pre><code>    private AsyncTask&lt;Void, Void, Void&gt; fillList = new AsyncTask&lt;Void, Void, Void&gt;() {
  
      @Override
      protected Void doInBackground(Void... params) {
          addListItems();
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
          for (int i = 1; i &lt; getListView().getChildCount()-1; i = i+2) {
              LOGI(TAG, "for-loop " + String.valueOf(i));
              getListView().getChildAt(i).setBackgroundColor(getSherlockActivity().getResources().getColor(R.color.light_green));
          }
      }   
  };
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I have done a bit of logging and found out that, if I am adding more elements than visible on the screen and check for the ListViews child count, the ListView only holds the children which are initially visible to the screen, the rest seems to be loaded/added when scrolling is done. </p>