user3835814
user3835814

Reputation: 71

Why is the fragment_main.xml missing in the ADT Bundle 20140702?

According to the instructions that Building a Simple User Interface on the website of Android Developers, I am goint to open the fragment_main.xml file from the res/layout/ directory with the Eclipse. But based on the ADT Bundle 20140702, there is only the activity_main.xml in the res/layout. Or fragment_main.xml can be found on the version 20140321.

Upvotes: 6

Views: 3273

Answers (4)

user2570265
user2570265

Reputation: 11

I created a new fragment_main.xml file as per above but make sure in the MainActivity.java you change this line of code:
from
setContentView(R.layout.activity_main);
to
setContentView(R.layout.fragment_main);

Upvotes: 1

user3835814
user3835814

Reputation: 71

While creating the new android application project,choose "Blank Activity with Fragment" option on the page "Create Activity". Then, we can find the fragment_main.xml.

Upvotes: 1

Divyanshu Jimmy
Divyanshu Jimmy

Reputation: 2752

By default when you make a new Android app project on yours ecclipse IDE , the default layout name is -

activity_main.xml

Which is a blank xml layout .

So you need to code yours fragment_main.xml under res/layout/ directory , as per yours implementation chosen at Android developers page

steps - right click res/layout/ > choose new > new android xml file > give the file name as fragment_main.xml and write yours code in it

or

just right click activity_main.xml > refactor > rename to fragment_main.xml

Upvotes: 1

Zolnoor
Zolnoor

Reputation: 699

Depending on what IDE you are using, creating a fragment layout for your main activity may only be an option now. If my memory serves me correctly I believe the automatically created fragment was prevalent in all IDEs at the time that tutorial was written.

Just use activity_main.xml instead of this fragment_main.xml and the tutorial will work fine. OR you can also right-click on the layout folder and create a new XML layout file and name it fragment_main.xml

Upvotes: 2

Related Questions