Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: TabHost - passing Parameters to Fragments

I am working on a TabHost with a WebView inside of each Fragment. What I do is:

for(int i = 0; i < numberOfTabs; i++){
        mTabManager.addTab(mTabHost.newTabSpec(tabNames[i]).setIndicator(tabNames[i]),
                Web.class, null);
 }

How can I pass parameters to each Fragment. In this case I want to pass an URL to each Fragment inside the TabHost.

Thx in advance.

like image 585
Bins Ich Avatar asked Oct 19 '12 13:10

Bins Ich


1 Answers

Finally I get the solution. You can pass parameters using a Bundle in the last parameter of "addTab" where you have "null".

for(int i = 0; i < numberOfTabs; i++){
        Bundle b = new Bundle();
        b.put...
        mTabManager.addTab(mTabHost.newTabSpec(tabNames[i]).setIndicator(tabNames[i]),
                Web.class, b);
 }

And then in the Fragment you can get the Bundle with getArguments().

I hope it will be useful for someone in the future

like image 56
Marta Rodriguez Avatar answered Oct 19 '22 09:10

Marta Rodriguez