How to make a button open up a new page (Layout)

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

How to make a button open up a new page (Layout)

Postby PhireBurner » Mon Mar 28, 2011 2:44 am

Hello Their :),


I am wondering how I could make a button open up a new page or layout. I am making a app that has a list of stories and I want the user to press on the button in order for him to open up a new page that displays the story. I know a little bit of java and any more advice will be helpful :).




Thank youuu!
PhireBurner
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Mar 28, 2011 2:40 am

Top

Re: How to make a button open up a new page (Layout)

Postby gqgk » Mon Mar 28, 2011 6:26 am

Well I'm assuming you know how to get something running off of a button, if not just let me know. But this is the code for use in your method:
Code: Select all
Intent intent = new Intent(this, YOUR_CLASS_NAME_WITH_THE_NEW_VIEW.class);
       startActivity(intent);


then in the xml you need to add:
Code: Select all
<activity android:name=".YOUR_CLASS_NAME_WITH_THE_NEW_VIEW." android:label="@string/app_name" />


Then of course set up your layout and do the standard code for a layout. Thats the complex but as far as I know the most correct way (not the only way) because it allows the back button to be used. However in your circumstance I'm not sure that's necessary. I believe you can just set up the layout and use:
Code: Select all
setContentView(R.layout.YOUR_LAYOUT_NAME);


Hope this helps... I'm relatively new to android as well so I'm not the person to ask as far as the drawbacks/advantages for each
gqgk
Freshman
Freshman
 
Posts: 8
Joined: Fri Mar 25, 2011 6:46 am

Re: How to make a button open up a new page (Layout)

Postby Nomad0404 » Tue Mar 29, 2011 1:52 pm

Just to point out the middle part labelled 'in the xml' is actually in the Manifest.
Nomad0404
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Mar 07, 2011 10:23 pm

Re: How to make a button open up a new page (Layout)

Postby ghuu » Tue Apr 26, 2011 1:41 pm

Hi, every one! I have a question, how to make this, but with several buttons and that by pressing them appeared same xml, but with the different content undertaking from others activity?
ghuu
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Apr 26, 2011 1:14 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests