安卓:TabHost - 参数传递到片段 [英] Android: TabHost - passing Parameters to Fragments

查看:140
本文介绍了安卓:TabHost - 参数传递到片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作一TabHost每个片段内的WebView。
我做的是:

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);
 }

我怎样才能将参数传递给每一个片段。在这种情况下,我想一个URL传递给TabHost内的每个片段。

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

Thx提前。

推荐答案

最后我得到的解决方案。您可以通过在addTab最后一个参数使用捆绑,你有空的参数。

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);
 }

然后在片段你可以得到getArguments捆()。

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

我希望这将是有用的人,将来

I hope it will be useful for someone in the future

这篇关于安卓:TabHost - 参数传递到片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆