Change Framelayout tabcontent background color
<p>I am trying to change the background color of a framelayout's background color based on which tab is selected. The app keeps crashing when I selected my lunch tab. Here is the main.xml:</p>

<pre><code>    ?xml version="1.0" encoding="utf-8"?&gt;

&lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"&gt;
    &lt;LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"&gt;
        &lt;FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" 
            android:layout_height="0dip"
            android:layout_weight="1" 
            android:padding="20dip" 
            android:background="#fff"/&gt;

        &lt;RadioGroup android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:orientation="horizontal"
            android:checkedButton="@+id/first" 
            android:id="@+id/states"&gt;
            &lt;RadioButton android:id="@+id/first" 
            android:background="@drawable/button_radio"
                android:width="106.6dip" 
                android:height="70dip" /&gt;
            &lt;RadioButton android:id="@+id/second" 
            android:background="@drawable/button_radio"
                android:width="106.6dip" 
                android:height="70dip" /&gt;
            &lt;RadioButton android:id="@+id/third" 
            android:background="@drawable/button_radio"
                android:width="106.6dip" 
                android:height="70dip" /&gt;
        &lt;/RadioGroup&gt;

        &lt;TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:gravity="center" 
            android:visibility="gone" /&gt;
    &lt;/LinearLayout&gt;
&lt;/TabHost&gt;
</code></pre>

<p>Here is my mainActivity's code:</p>

<pre><code>public class MainActivity extends TabActivity{//implements TabHost.TabContentFactory {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


     Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, Breakfast.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("breakfast").setIndicator("Breakfast").setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, Lunch.class);
        spec = tabHost.newTabSpec("lunch").setIndicator("Lunch").setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Dinner.class);
        spec = tabHost.newTabSpec("dinner").setIndicator("Dinner").setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(2);


    setupUI();
}

private void setupUI() {
    RadioButton rbFirst = (RadioButton) findViewById(R.id.first);
    RadioButton rbSecond = (RadioButton) findViewById(R.id.second);
    RadioButton rbThird = (RadioButton) findViewById(R.id.third);
    rbFirst.setButtonDrawable(R.drawable.ebay);
    rbSecond.setButtonDrawable(R.drawable.flickr);
    rbThird.setButtonDrawable(R.drawable.skype);
    RadioGroup rg = (RadioGroup) findViewById(R.id.states);
    rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        public void onCheckedChanged(RadioGroup group, final int checkedId)     {
            switch (checkedId) {
            case R.id.first:
                getTabHost().setCurrentTab(0);
                break;
            case R.id.second:
                getTabHost().setCurrentTab(1);
                break;
            case R.id.third:
                getTabHost().setCurrentTab(2);
                break;
            }
        }
    });
}

}
</code></pre>

<p>Finally, here is my Lunch.java. I am simply trying to change the color to green right now as a test. I am wondering though would it be better to just create a new .xml file and setContentView to this .xml file.</p>

<pre><code>public class Lunch extends Activity {
private FrameLayout mainFrame;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mainFrame = (FrameLayout) findViewById(android.R.id.tabcontent);

    mainFrame.setBackgroundColor(Color.GREEN);

    TextView textview = new TextView(this);
    textview.setText("This is the Lunch tab");
    setContentView(textview);
}

}
</code></pre>

<p>Thanks!</p>
