title: Change Layout-background on click programmatically
body: <p>I can change the background of a LinearLayout via xml by writing</p>
  
  <blockquote>
    <p>android:background="@drawable/overview"</p>
  </blockquote>
  
  <p>to my LinearLayout.</p>
  
  <p>However I can't do that programmatically. I tried following:</p>
  
  <blockquote>
    <p>LinearLayout horizontal_menu = new LinearLayout(this);
    ...
       horizontal_menu.setBackgroundResource(getResources().getInteger(R.drawable.overview));</p>
  </blockquote>
  
  <p>and also that source of code:</p>
  
  <blockquote>
    <p>horizontal_menu.setBackground(getResources().getDrawable(R.drawable.overview));</p>
  </blockquote>
  
  <p>First try throws an RuntimeException at runtime, the second line seems to do nothing -> no errors, no exceptions, no changing background on clicking...</p>
  
  <p>--> overview.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; 
  &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;   
  &lt;item android:state_focused="true" android:drawable="@color/half_transparent"/&gt; 
  &lt;item android:state_pressed="true" android:drawable="@color/half_transparent" /&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>I hope that anyone can help me!</p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>LinearLayout content = (LinearLayout)findViewById(R.id.LinearLayout); 
  LinearLayout horizontal_menu = new LinearLayout(this); 
  horizontal_menu.setOrientation(LinearLayout.HORIZONTAL); 
  horizontal_menu.setBackgroundResource(getResources().getInteger(R.drawable.overv‌​iew)); 
  content.addView(horizontal_menu);
  </code></pre>