TKV
TKV

Reputation: 2653

Working with more than one xml file in android

I am new to android development.

If I have more than one xml file, other than the main.xml, then how can I call the other files?

Upvotes: 0

Views: 1229

Answers (3)

Nanne
Nanne

Reputation: 64399

You can either call the different xml files when needed, like so:

 setContentView(R.layout.yourname.xml);

If you need to load the contents of one xml, and put it in a view, then you can use an inflater to fetch a view from an xml that isn't 'loaded'. There is also an addContentView() command, but I don't think you'll need that for now :)

Upvotes: 1

Uroš Podkrižnik
Uroš Podkrižnik

Reputation: 8647

create new activity. (add new .java). then in main.java call
Intent myIntent = new Intent(this, NEW_ACTIVITY.class);
startActivityForResult(myIntent, 0);

and on start of onCreate OF NEW_ACTIVITY add

 this.setContentView(R.layout.NEW_XML);

in manifest.xml you must also add

<activity android:name=".NEW_ACTIVITY"></activity>

Upvotes: 1

Maxim
Maxim

Reputation: 3006

You should call it by name of the file. For examole for main.xml you call it as R.layout.main, so for my_menu_activity.xml it would be R.layout.my_menu_activity

Upvotes: 2

Related Questions