title: Android - background change from Java code
body: <p>my problem is, I have custom listView filled from Runnable returnRes. It fills particular data in layout I have named as lay (R.id.layoutList). My aim is to have different colour for each lay in my listView, I want to switch colours between each. 1st is dark blue, second light blue, thir dark blue and so on... This code is doing well, but with no result, my custom listView is still black, when I change it in XML, it is changing, but not when it is set from Java. Any ideas? </p>
  
  <p>Thanks</p>
  
  <pre><code>private Runnable returnRes = new Runnable() {
  
      @Override
      public void run() {
          if(myTasks != null &amp;&amp; myTasks.size() &gt; 0){
              TasksAdapter.notifyDataSetChanged();
  
              LinearLayout lay=(LinearLayout)findViewById(R.id.layoutList);
  
              for(int i=0;i&lt;myTasks.size();i++){
                  TasksAdapter.add(myTasks.get(i));
                  if(i&gt;0){
                      if(i%2==0){
                          lay.setBackgroundColor(R.color.background);
                      }
                  }else{
                      if(i&gt;0){
                          lay.setBackgroundColor(R.color.lightBlue);
                      }
  
                  }
              }
          }
          ProgressDialog.dismiss();
          TasksAdapter.notifyDataSetChanged();
      }
    };
  </code></pre>