Question

I have a listview withcin a activity and when someone clicks on an item in the listview I want to start a activity of type TabActivity.

Any ideas on why it's not working?

    list.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            JobListRowData item = jobListAdapter.getItem(position);
                Intent myIntent = new Intent(view.getContext(), EventsTabs.class);                  
                startActivity(myIntent);
            }  }    });


    public class EventsTabs extends TabActivity {
    private TabHost mTabHost;

    @Override 
    public void onCreate(Bundle savedInstanceState) {  
      setContentView(R.layout.event_main);
      Resources res = getResources(); 
      TabHost tabHost = getTabHost();  
      TabHost.TabSpec spec;  
      Intent intent;  
      intent = new Intent().setClass(this, EventsTabs.class);    
      spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.icon)).setContent(intent);    
      tabHost.addTab(spec);    
      intent = new Intent().setClass(this, EventsTabs.class);    
      spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.icon)).setContent(intent);
      tabHost.addTab(spec);    
      intent = new Intent().setClass(this, EventsTabs.class);    
      spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.icon)).setContent(intent);
      tabHost.addTab(spec);    
      tabHost.setup(); 
     }  

    }

For some reason I get a : 12-06 13:37:47.607: ERROR/AndroidRuntime(346): Caused by: java.lang.IllegalStateException: Activities can't be added until the containing group has been created.

Was it helpful?

Solution

Try adding this to your code..

 LocalActivityManager mlam = new LocalActivityManager(this, false);

  mlam.dispatchCreate(savedInstanceState);
  tabHost.setup(mlam );

EDIT: you should set up the tabhost before adding the tabs to it..

You should call set up first like this...

TabHost tabHost = getTabHost();  
  TabHost.TabSpec spec;  
   tabHost.setup(); //Move set up here

  Intent intent;  
  intent = new Intent().setClass(this, EventsTabs.class);    
  spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.icon)).setContent(intent);    
  tabHost.addTab(spec);    
  intent = new Intent().setClass(this, EventsTabs.class);    
  spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.icon)).setContent(intent);
  tabHost.addTab(spec);    
  intent = new Intent().setClass(this, EventsTabs.class);    
  spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.icon)).setContent(intent);
  tabHost.addTab(spec);    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top