views:

2553

answers:

1

Hi

Im trying to setup some tabs for my android application, but i got stuck.

I cant find a way to communicate between the tabs..

I got 2 tabs.


|Search|Result|

The search tab is simply showing a TextEdit and a "Search" button. Hitting the search button should make my app change to the result tab and display the result.

i have added the tabs as activities using new intents as

TabHost host=getTabHost();

host.addTab(host.newTabSpec("one")
.setIndicator("Search")
.setContent(new Intent(this, SearchTabActivity.class)));
host.addTab(host.newTabSpec("Result")
.setIndicator("Android")
.setContent(new Intent(this, ResultTabActivity.class)));

Now i cant find a way for SearchTabActivity to display ResultTabActivity and alter its view...

Im looking forward for any tip.

+2  A: 

You definitely want to reconsider using Activities as the content of your tabs. The more standard approach is to use one Activity that uses Tabs to only show part of the layout when a particular tab is selected.

The Android documentation has an excellent worked example, check out Hello, TabWidget.

Alternative

If for some reason you do need to use Activities, you can pass information between them by either adding values to the extras bundle within the Intent your using to open each Activity, or by extending the Application class.

By extending the Application class (and implementing it as a Singleton) you get an object that will exist whenever any of your application components exist, providing a centralized place to store and transfer complex object data between application components.

Reto Meier