Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch from the main.xml layout to another layout

I have a basic Android question here:

I have a main.xml layout that loads up when the app is launched. This page has a menu button that I'd like to (when clicked) send the user to another layout (about.xml).

I doubt this is the right. When clicked this command is kicked in:

setContentView(R.layout.about);

And it seems to work, I do see the about.xml page, but I cannot navigate back to the main.xml layout when I hit the BACK button on my Android device, the app just closes.

I doubt that this is the right way to navigate between xml layout files. Can you please help or point me to a page that spells this out for a computer programmer beginner like myself?

Thank you very much,

Pat

EDIT: Thanks for all the answers you helped point me in the right direction. In an effort to help future noob programmers like myself to understand Activities, here's a great simple tutorial that I found online that mapped it out for us beginners!

http://www.warriorpoint.com/blog/2009/05/24/android-how-to-switch-between-activities/

like image 487
PAMUNOZ Avatar asked May 10 '11 15:05

PAMUNOZ


People also ask

How do I create a layout in another layout?

To efficiently reuse complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout. Reusing layouts is particularly powerful as it allows you to create reusable complex layouts. For example, a yes/no button panel, or custom progress bar with description text.

What is the correct way to attach a layout into your activity?

You can declare a layout in two ways: Declare UI elements in XML. Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts. You can also use Android Studio's Layout Editor to build your XML layout using a drag-and-drop interface.

What is a relative layout?

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).

What an XML layout file contains?

The XML layout file contains at least one root element in which additional layout elements or widgets can be added to build a View hierarchy. Following is the example: XML.


1 Answers

Do you have a separate activity for your about page? Generally for each screen you create a new activity. When you go to new screen , the new activity will be stacked over the first screen activity. When you click Back on android device, the previous activity will be popped up.

like image 130
yogsma Avatar answered Oct 05 '22 03:10

yogsma