打开活动的特定片段

时间:2015-08-20 21:02:14

标签: android android-fragments

我有一个向导,我在每个屏幕上都使用片段,在最后一个活动中,我有一个按钮,可以将用户发送到设置的辅助功能,当用户返回我的应用程序时,该按钮必须更改为其他内容,问题是当用户回到我的应用程序时按钮没有改变所以我想关闭活动并在最后一个片段上重新打开它,这样按钮就能正确地进行更改

如何在"ok 1"上打开活动?

我使用适配器来设置片段的顺序:

SecurityWizardFiveFragment();

My SecurityWizardActivity:

    @Override
public Fragment getItem(int position) {

    switch(position)
    {
    case 0:
        return new SecurityWizardOneFragment();
    case 1:
         return new SecurityWizardTwoFragment();            
    case 2:
        return new SecurityWizardThreeFragment();
    case 3:
        return new SecurityWizardFourFragment();
    case 4:
        return new SecurityWizardFiveFragment();

    }
    return null;

}

SecurityWizardFiveFragment,在这里我将用户发送到辅助功能:

    @Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.security_wizard_info_tab);
    // Creating The ViewPagerAdapter and Passing Fragment Manager, Titles fot the Tabs and Number Of Tabs.
    adapter =  new SecurityWizardViewPagerAdapter(getSupportFragmentManager(),Titles,Numboftabs,this);

    // Assigning ViewPager View and setting the adapter
    pager = (ViewPager) findViewById(R.id.pager);       

    pager.setAdapter(adapter);      

    // Assiging the Sliding Tab Layout View
    tabs = (SlidingTabLayout) findViewById(R.id.tabs);
    tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available width

    // Setting Custom Color for the Scroll bar indicator of the Tab View
    tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
                @Override
                public int getIndicatorColor(int position) {
                    return getResources().getColor(R.color.tabsScrollColor);
                }
            });

    //Setting the ViewPager For the SlidingTabsLayout
    tabs.setViewPager(pager);



}

private void installShortcut() {
    final Intent shortcutIntent = new Intent(getApplicationContext(), SecurityWizardActivity.class);
    shortcutIntent.setAction(Intent.ACTION_MAIN);
    shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

    final Intent intent = new Intent();
    intent.putExtra("duplicate", false);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher_lycos));
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(intent);
}

1 个答案:

答案 0 :(得分:-1)

制作全局变量securityWizardPage

在我的SecurityWizardActivity

pager.setCurrentItem(Globals.securityWizardPage);

然后当我想打开一个特定的片段时:

Globals.securityWizardPage = 4;