首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将字符串从子选项卡活动传递到父选项卡

将字符串从子选项卡活动传递到父选项卡
EN

Stack Overflow用户
提问于 2012-07-08 11:35:41
回答 1查看 1K关注 0票数 1

我有一个活动名称"Tabs“。它启动了4个不同的选项卡,每个选项卡都有自己的活动。它使用:

代码语言:javascript
复制
th = (TabHost) findViewById(R.id.tabhost);
    th.setup(this.getLocalActivityManager());
    TabSpec specs = th.newTabSpec("Tag1");
    Intent tabSelection = new Intent (this, ProfileSettings.class);

    tabSelection.putExtras(gotSettings);
    specs.setContent(tabSelection);
    specs.setIndicator("Settings",
            getResources().getDrawable(R.drawable.ic_menu_friendslist));
    th.addTab(specs);

    specs = th.newTabSpec("Tag2");
    tabSelection = new Intent (this,InternationalRoamingService.class);
    specs.setContent(tabSelection);
    specs.setIndicator("IRS", getResources().getDrawable(R.drawable.ic_menu_mapmode));
    th.addTab(specs);

    specs = th.newTabSpec("Tag3");
    tabSelection = new Intent (this,Call.class);
    specs.setContent(tabSelection);
    specs.setIndicator("Call", getResources().getDrawable(R.drawable.call));
    th.addTab(specs);

    specs = th.newTabSpec("Tag4");
    tabSelection = new Intent (this,WebSMS.class);
    specs.setContent(tabSelection);
    specs.setIndicator("SMS", getResources().getDrawable(R.drawable.ic_menu_start_conversation));
    th.addTab(specs);

将捆绑包"gotSettings“从父级传递到子级没有任何问题。但是,我如何从子活动更新包的值,或者将值从子活动传递到父活动?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-08 11:51:48

有两种方法可供选择:

http://www.vogella.com/articles/AndroidIntent/article.html#usingintents_sub

  • Another方式是使用静态参数,你可以在你的子活动中更改它,然后在你的父活动中使用它。
  • 你可以使用StartActivityForResult,这是一个例子。例如:在具有'ChildActivity‘类名public static int myValue;的子活动中添加下面这一行,然后为它设置一个参数myValue=25;并在父活动中使用它:
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11380465

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档