views:

99

answers:

0

I have a working TabView in Android, and would like to have a few more items available by pushing the menu button. I currently have a menu there, and can start new activities, but the content makes the TabView disapear rather than putting the content in the TabView. Is there any way for me to force / allow new Activities to open in the tabview rather than leaving Tabview and opening its own window?

I have things very simple. Here is the Tabs.xml file:

<?xml version="1.0" encoding="utf-8"?>
<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">    
<LinearLayout        
android:orientation="vertical"        
android:layout_width="fill_parent"        
android:layout_height="fill_parent"        
android:padding="5dp">        
<TabWidget            
android:id="@android:id/tabs"            
android:layout_width="fill_parent"            
android:layout_height="wrap_content" />        
<FrameLayout            
android:id="@android:id/tabcontent"            
android:layout_width="fill_parent"            
android:layout_height="fill_parent"            
android:padding="5dp" />  
</LinearLayout>
</TabHost>

Here is how the tabs are populated:

setContentView(R.layout.tabs); 

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

 intent = new Intent().setClass(this, RestaurantsActivity.class);      
 spec = tabHost.newTabSpec("Restaurants").setIndicator("Restaurants",res.getDrawable(R.drawable.ic_tab_restaurants)).setContent(intent);    
 tabHost.addTab(spec); 

 intent = new Intent().setClass(this, RestaurantsMap.class);    
 spec = tabHost.newTabSpec("Map").setIndicator("Map",res.getDrawable(R.drawable.ic_tab_categories)).setContent(intent);    
 tabHost.addTab(spec); 

 intent = new Intent().setClass(this, AccountActivity.class);    
 spec = tabHost.newTabSpec("Shopping").setIndicator("Shopping",res.getDrawable(R.drawable.ic_tab_brands)).setContent(intent);    
 tabHost.addTab(spec);

And here is how the menu is done:

public boolean onCreateOptionsMenu(Menu menu){

  MenuInflater inflater = getMenuInflater();

  inflater.inflate(R.menu.menu, menu);

  return true; 

  }


 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
     switch(item.getItemId()) {
     case R.id.account:
   startActivity(new Intent().setClass(this, AccountActivity.class));  
     break;
     case R.id.search:
      startActivity(new Intent().setClass(this, SearchActivity.class));  
     break;
     case R.id.scanner:

     break;
     default:
      return false;
     }

     return true;
 }

Basically I want those new activities / intents to open up in the Framelayout, but instead they create a new window outside of TabView. Do I need a RelativeView in tabs.xml?