tags:

views:

39

answers:

2

I would like to access the public method of an Activity run by a TabActivity using:

TabHost tabHost = getTabHost();
Intent intentMsgsView = new Intent().setClass(this, TeamHuddleScreenMsgsView.class);
tabHost.addTab(tabHost.newTabSpec("msgs").setIndicator("Messages").setContent(intentMsgsView));

Basically, what I what is to let the parent Activity call a method in child Activity in order to do something. Is this possible?

I did try this:

((TeamHuddleScreenMsgsView)getTabHost().getCurrentTabView().getContext()).refreshModel();

but I'm encountering a ClassCastException. It seems that the getContext() still gives the TabActivity. Any help on how to get the child Activity?

Thanks.

A: 

This will be much simpler if you would not put activities in your tabs and just put views in your tabs, as that will mean there is only one activity. Here is a sample project showing how this is done.

There is a getActivity() method on ActivityGroup (parent class of TabActivity) that is undocumented but might be what you want.

CommonsWare
+1  A: 

Listen to what CommonsWare says here, I have gone this route and it was a horrible mistake, but here is how you do it.

((SportsActivity)getLocalActivityManager().getCurrentActivity()).setLayout(R.layout.helpview);

Here setLayout is a public method I made in SportsActivity

schwiz
awesome! it worked! and i agree, it seems that using Views instead of Activities would be better. thanks guys!
firnnauriel