1

is it possible to open a fragment B from fragment A by tapping on a button in fragment A? Both fragments are part of a main FragmentActivity. How can I handle that?

Open fragment B from fragment A

EDIT:

The Tabs are implemened like that:

 ActionBar actionbar = getSupportActionBar();
    actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);




    Tab tab1 = actionbar.newTab().setText("");
    Tab tab2 = actionbar.newTab().setText("");

    tab1.setTabListener(new MyTabListener<AFragment>(this, "tab1",AFragment.class));
    tab2.setTabListener(new MyTabListener<BFragment>(this, "tab2",BFragment.class));

    tab1.setIcon(R.drawable.ic_a);
    tab2.setIcon(R.drawable.ic_b);

    actionbar.addTab(tab1,0,true);
    actionbar.addTab(tab2,1,false);

Thank you :)

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
cuSoon2013
  • 255
  • 6
  • 12
  • 1
    http://stackoverflow.com/questions/9831728/start-a-fragment-via-intent-within-a-fragment. A link that should help you.http://stackoverflow.com/questions/7105099/how-to-call-fragment-from-fragment – Raghunandan Nov 11 '12 at 16:43
  • Yes, but the actual code will vary depending upon what those tabs are. Action bar tabs? `PagerTabStrip`? Something else? – CommonsWare Nov 11 '12 at 16:43

1 Answers1

0

Add below code to onClick():

public void onClick(View v) {
            Fragment fragment = new projectInformationFragment();
            FragmentTransaction transaction = 
            getActivity().getSupportFragmentManager().beginTransaction();
            transaction.replace(R.id.nav_host_fragment, fragment);
            transaction.addToBackStack(null);
            transaction.commit();
        }
M Karimi
  • 1,991
  • 1
  • 17
  • 34