john.zli
john.zli

Reputation: 561

Android ADT: No fragment_main.xml, only activity_main.xml

I'm trying to learn how to program android applications, so I downloaded the ADT bundle that google supplied, and I tried following the tutorial that allowed me to create a simple application. However, during the procedures, there are several instructions telling me to open up the fragment_main.xml file, but my layout/res/ directory did not have this file, only the activity_main.xml file. Furthermore, when creating new Android activities, there was never an option to name my fragment layout, indicating that eclipse just doesn't create it for some reason. I didn't think this would be an issue at first (I just edited activity_main instead), until I realized that the tutorial wanted us to use the some information from the fragment class or xml file.

Does anyone know why my Eclipse IDE is not creating a fragment_main.xml? I will try to supply more details if necessary.

Upvotes: 11

Views: 10839

Answers (4)

old_soul_on_the_run
old_soul_on_the_run

Reputation: 289

While creating the new Android Project in one of the panels select "Blank activity with Fragment" instead of default selection "Blank Activity". The Android Developer tutorial does not say anything about it. Doing so will create the file fragment_main.xml in res/layout/ which is needed to continue subsequent steps.

Upvotes: 5

intellectual_stretch
intellectual_stretch

Reputation: 121

Try creating a new project with "Blank Activity with Fragment". I hope this is helpful.

Upvotes: 1

Prabindh
Prabindh

Reputation: 3504

Based on the versions you indicated in the comment response, I think updating to the later versions (22.6+) would help, as discussed in https://code.google.com/p/android/issues/detail?id=67421

Upvotes: 4

EngineerLuna
EngineerLuna

Reputation: 1

Open MainActivity.java from the src/(package name file)/ directory. Then inside the java file there is a method called OnCreate() that has setContentView(R.layout.activity_main) as default.

Change that to R.layout.activity_main to R.layout.fragment_main so instead of having setContentView(R.layout.activity_main) you'll have setContentView(R.layout.fragment.main)

Once that's done change the name of the activity_main.xml file under the /res/layout/ directory to fragment_main.xml

Thanks for that Onik!

Upvotes: 0

Related Questions