[KEY : ANDROID FRAGMENT, ACTIVITY, ADD FRAGMENT TO ACTIVITY]
Add Fragment to Activity
- Create simple activity with xml.
- Go to xml file add framelayout and assign id to it as follow:
<FrameLayout android:id="@+id/your_frame_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:clickable="true" /> - Create java class with name like "MyFirstFragment.java" and extend fragment.
- Go to activity add the following code :
Fragment myFragment = new MyFirstFragment(); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fTransaction = fragmentManager .beginTransaction() .replace(R.id.your_frame_layout, bodyFragment) .addToBackStack("myprofile"); fTransaction.commit();
No comments:
Post a Comment