Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to call function of Activity inside of tab from the tabhost

I have a tabhost with three tabs. Each is an activity. I would like to have a button which is in the action bar, the bar along the top with common buttons, call functions of the tab which is active.

For example, an add function which could add something different to each tab depending on what tab was present when you clicked the button.

So, I am aksing how to call a function in Activity A from the tabHost.

And if that wont work, perhaps I can update the database from the tabhost and then refresh the tab content. Would that be easier?

Thank you all for you time and support.

like image 438
Anthony Graglia Avatar asked Mar 16 '11 00:03

Anthony Graglia


1 Answers

I used the following code within my TabActivity class to switch tab then call a public method defined in the activity of the tab:

getTabHost().setCurrentTab(0);
Activity MyActivity = this.getCurrentActivity();
MyActivity.myMethod();

Hopefully helpful to someone looking for the answer to this question.

like image 172
Dan Kilpatrick Avatar answered Sep 26 '22 18:09

Dan Kilpatrick