How to navigate from one Fragment to another?

那年仲夏 提交于 2019-12-03 21:19:22
Siu

Add this to your OnClickListener:

CustomView cv = new CustomView();
FragmentManager fm= getFragmentManager();
FragmentTransaction ft= fm.beginTransaction();
ft.replace(R.id.custom_view, cv);
ft.commit();

You need to add this to the RelativeLayout in your

custom_view.xml

android:id="@+id/custom_view"

Try this...place inside listener

// Create new fragment and transaction
Fragment newFragment = new ExampleFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();

// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);

// Commit the transaction
transaction.commit();

//Create one FrameLayout and give the id as fragment_view in your fragment_view1.xml and do like below

add this line in your layout fragment_view1.xml

 <FrameLayout
                android:id="@+id/fragment_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />



private class ButtonEvent implements OnClickListener
    {

CustomView custFra = new CustomView();
fragmentTransaction.replace(R.id.fragment_view, custFra).commit();


  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!