Android:TabHost - 将参数传递给碎片

Bin*_*Ich 10 android android-tabhost android-fragments actionbarsherlock

我正在使用每个片段内部的WebView进行TabHost.我所做的是:

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

如何将参数传递给每个片段.在这种情况下,我想将一个URL传递给TabHost中的每个Fragment.

Thx提前.

Mar*_*uez 22

最后我得到了解决方案.您可以使用"addTab"的最后一个参数中的Bundle传递参数,其中"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);
 }
Run Code Online (Sandbox Code Playgroud)

然后在Fragment中你可以使用getArguments()获得Bundle.

我希望将来对某人有用