5

I m trying to understand the concept of fragment on android. The official pages has some code snippets and a link mentioning the entire source code called FragementLayout.java. However on clicking it , I get redirected to this page

http://developer.android.com/tools/samples/index.html

Which says the source code is available in the samples directory where the sdk has been installed. I tried checking out samples of various different API levels (8, 11, 17) but could not find the source code for fragments tutorial. Does any body know where it is ?

Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126
  • 1
    I can't imagine why Google doesn't make this more clear somewhere, but `FragmentLayout.java` is one class found in an app called "Api Demos" that is distributed with the SDK. It can't be made a standalone app without a lot of whittling away of unrelated stuff. On v18, it's found in `sdk/samples/android-18/legacy/ApiDemos`. The app is meant to be built and installed as a whole. The `FragmentBasics.zip` mentioned below is an unrelated demo app specific to one of the "Getting Started" docs and has nothing to do with the OP. – jordanpg Jun 19 '14 at 14:26
  • Also, the page that you get redirected to mentioned in the OP seems to be a new, independent set of sample code that reflects the directory structure of the `samples/` directory. Most of the docs have not been updated to reflect this. The `legacy/` directory looks like what `samples/` used to look like prior to v18. – jordanpg Jun 19 '14 at 14:43

5 Answers5

1

I have that exact file in the samples folder of 13, 14 & 16.

For extra credit, I recommend checking out the Fragments demo of Action Bar Sherlock, since I believe it shows a better way of learning Fragments.

For more discussion about this, check out my question & the related answers:

You can see that I do not like the pattern in that tutorial, but there is good discussion for both approaches.

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
1

Make a new project using create project from existing sample. Choose maximum target name then Select Sample ApiDemo. Finish. Now go to ApiDemos->src->com.example.android.apis.app->FragmentLayout.java .Enjoy

MGDroid
  • 1,659
  • 2
  • 17
  • 32
0

Yes, it seems to be removed from the official Android online documentation.

However, it can be found in the downloadable "Samples for SDK" for each API level.

To download "Samples for SDK", using "Android 4.4.2 (API 19)" as an example:

  1. Open Android SDK Manager (E.g. Eclipse > Window > Android SDK Manager).
  2. Tick "Android 4.4.2 (API 19)" > "Samples For SDK".
  3. Install.

FragmentLayout.java will be found in a directory like

"C:\Program Files\Android\sdk\samples\android-19\legacy\ApiDemos\src\com\example\android\apis\app\FragmentLayout.java"

John Bentley
  • 1,676
  • 1
  • 16
  • 18
-1

You can find the Sample code as well as explanation in official Android Docs Here

Rajeev N B
  • 1,365
  • 2
  • 12
  • 24
-1

Just clic on this link to download the example from Android Developers wbesite : FragmentBasics.zip

Rémi F
  • 1,327
  • 12
  • 25