title: Android set widget background
body: <p>In my drawable-hdpi folder i have 4 image files (.png) to serve as the background of awidget. By default android:background="@drawable/goldgreenbg" is set for the LinearLayout. I created a preferences screen to let the user change the background.
  How to do that? I would like to use this code for it:</p>
  
  <pre><code>      if (listpref.equals("color1"))
            {
            Toast.makeText(EditPreferences.this,  "Black" + listpref, Toast.LENGTH_LONG).show();
  
            }
  
  else if (listpref.equals("color2"))
            {
                Toast.makeText(EditPreferences.this,  "Brown" + listpref, Toast.LENGTH_LONG).show();
            }
  </code></pre>
  
  <p>Update:
  Where shall i put this code to?
  MainActivity.java: for the activity
  UpdateService.java: for the widget
  EditPreferences.java: for the preferences
  Main.xml includes the listview and widgetlayout is id of it.</p>
  
  <pre><code>  setContentView(R.layout.main);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String listpref = preferences.getString("listPref", "n/a");              
    LinearLayout ll = (LinearLayout) findViewById(R.id.widgetlayout);
    if (listpref.equals("color1"))
    {
        Toast.makeText(MainActivity.this, "Black" + listpref, Toast.LENGTH_LONG).show();
        ll.setBackgroundDrawable(getResources().getDrawable(R.drawable.blackbg));
    }
    else if (listpref.equals("color2"))
    {
        Toast.makeText(MainActivity.this, "Brown" + listpref, Toast.LENGTH_LONG).show();
        ll.setBackgroundDrawable(getResources().getDrawable(R.drawable.brownbg));
    }
  </code></pre>