title: How to alternate row colors in android listview?
body: <p>I'm new to android development and i am facing an issue, I have a <code>listview</code> that is filled using an Array adapter, i want to make odd rows (items) in the <code>listview</code> has the color of 'red' for example and the even rows have the color of 'yellow'! how can i achieve this?</p>
  
  <p>here is the code <code>onCreate()</code> method:-<br> </p>
  
  <pre><code>//defining list view
      listView = (ListView)findViewById(R.id.listView);
      //defining data array list to store retrieved data from database
      data = new ArrayList&lt;String&gt;();
      adapter=new ArrayAdapter&lt;String(this,android.R.layout.simple_list_item_1, data);
      listView.setAdapter(adapter);
  </code></pre>
  
  <p><code>onPostExecute()</code> method:- <br></p>
  
  <pre><code>protected void onPostExecute(ArrayList&lt;ProductionCommentsTable&gt; result) {
          // TODO Auto-generated method stub
          for (int i = 0; i &lt; result.size(); i++) {       
              data.add("Date: " + result.get(i).getDate().substring(0, 10) + newline + newline +
                      "Item: " + result.get(i).getItem() + newline + newline +
                      result.get(i).getComments());
                  if ( i % 2 == 0) {
                      listView.setBackgroundColor(Color.RED);
                  } else {
                      listView.setBackgroundColor(Color.YELLOW);
                  }
          }
          adapter.notifyDataSetChanged();
  </code></pre>
  
  <p>Thanks in advance...</p>