Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

android - Open Fragment from another Fragment?

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 :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...