简体   繁体   English

如何将值从活动传递到选项卡活动

[英]how to pass value from activity to tabactivity

i have a activity,i want to pass value from activity to tabactivity so that to change the tab of tabactivity,mu code: activity:我有一个活动,我想将值从活动传递到 tabactivity,以便更改 tabactivity 的选项卡,mu 代码:活动:

           intent.putExtra("tabNumber", "2");
                  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setClass(context, TabSubActivities.class);

the follow code in the tabActivity: tabActivity 中的以下代码:

 Bundle bundle = this.getParent().getIntent().getExtras();
    //Bundle bundle = this.getIntent().getExtras();
    if (bundle != null) {
        String tabNumber = bundle.getString("tabNumber");
        if (tabNumber != null && !tabNumber.equals(""))
        {
             int No= Integer.getInteger(tabNumber);
             Log.i("cc","aa");
            // ((TabActivity) getParent()).getTabHost().setCurrentTab(No);
        }
        else
        {
             Log.i("cc","bb");
            // ((TabActivity) getParent()).getTabHost().setCurrentTab(1);
        }
    }
    else
        {
            Log.i("cc","cc");
            //((TabActivity) getParent()).getTabHost().setCurrentTab(2);
          }

but i cannot get the Log information,and give me mistake,how to form activity to change tabactivity tab,for example: tabactivity default show tab(0),i want to show tab(1),but i want the activity not belongs to tavactivty to change the tavactivty tab但我无法获取日志信息,并给我错误,如何形成活动以更改选项卡活动选项卡,例如:选项卡活动默认显示选项卡(0),我想显示选项卡(1),但我希望活动不属于tavactivty 更改 tavactivty 选项卡

You can use Intent Filters for that purpose.您可以为此目的使用 Intent 过滤器。 Just broadcast your event in your activity and handle it in your tabActivity.只需在您的活动中广播您的事件并在您的 tabActivity 中处理它。

int No= Integer.getInteger(tabNumber) this line is mistake,i used int No= Integer.parseInt(tabNumber); int No= Integer.getInteger(tabNumber) 这行是错误的,我使用 int No= Integer.parseInt(tabNumber);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM