Fragment


 

  1. Static Fragment
  2. Dynamic Fragment

 

1. Static Fragment
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package, create new class, FramentOne.java and add following code :

Step 5 : Open res -> layout, create fragment_one.xml and add following code :

Step 6 : Open src -> package, create new class, FramentTwo.java and add following code :

Step 7 : Open res -> layout, create fragment_two.xml and add following code :

Step 8 : Open AndroidManifest.xml and add following code :

ScreenShot:frag
Download SourceCode

 

2. Dynamic Fragment
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package, create new class, FramentOne.java and add following code :

Step 5 : Open res -> layout, create fragment_one.xml and add following code :

Step 6 : Open src -> package, create new class, FramentTwo.java and add following code :

Step 7 : Open res -> layout, create fragment_two.xml and add following code :

Step 8 : Open AndroidManifest.xml and add following code :

ScreenShot:dy_frag
Download SourceCode