Tuesday, June 7, 2011

Android Layout Editing and Resource Handling 3

Android Layout Tutorial 03
Hi all ....... 

Did you enjoy with layout editing? No we are going to move to see the java codes how can we use the objects in the layout and how add multiple layouts to an application. Obviously there are many different interfaces comes up when we work with application, some interfaces are containing Forms, Information, graphical decorated interface and many more. So it should be able to add many interfaces on multiple layout files and also should have facility to change the visible layout too. With this post I'm going to discuss about those operations.

[Important]


Let's add new layout file to our Android  application.

1. Open the layout folder (where your main.xml located) 
2. Right click on the "Layout' folder and go to      New > Other > Android > Android xml file

3. Now fill the "New Android XML File " form and finish. It basically ask about the project name, name of the file, etc. Select "Layout" when it ask "What type of resource would you like to create?"
Don't do any with resource configuration for now, and select linearLayout (because I think you are familiar with it). Click finish :)

4.OK, now you can see new layout xml have added to the Layout folder, just select it and do changes what you want. see it work same as before.






5. now run your application and check weather it shows in your virtual phone. CAN YOU SEE ?


:-(  Ya!  still it shows old main.xml layout. Now we should instruct to the application to show our new layout instead of main.xml. (in my case new file named as second.xml, it can be any as you preferred)


Now it is time to open our java code :-o , but don't worry still I just want to change some text only no any programming yet.   :) 


Change the main layout in Android application


1. open src folder and package
2. You can see the application activity file with you given name when you create the application. If you cant remember just go to previous Android Hello World Post, and see the given for activity and package name. Here I continually used same application, you can compare the names with my src content also. 




3. open your Activity file (in my case it is "MyMain.java"), and change the it as shown in the image.
setContentView(R.layout.main); ----change to ----->      setContentView(R.layout.second);

because my newly added layout is "second.xml" it may different in your application, add the name you created before. 
4. NOW RUN THE APPLICATION AND SEE THE DIFFERENCE :)

Actually in this post I just what you to show we can add many layouts to one application and how those gonna view on the application. still I didn't do any clarification about how this setContentView () function working and about the Activity file. there are lot to learn about those things. 

This may be a short post comparing with other posts, because I'm bit busy with my work these days and I hope to cover element property handling part too, in this post but I'll do it in my next post. 
And there are in depth discussions about layout and styling about Interfaces should discuss within next posts.

Thank you all for reading :)

Next Post :
 Change Properties of the Interface Element Manually and with Activity File.
;) need a bit about programming :)



By MIthila Karunarathna

No comments:

Post a Comment