Tips: There are several good links or some news are recommended to surf in the right panel of this blog.
Android think of ways to reduce programmer works, using XML layout is one of it. Previously the one you build and run with those coding, is called "programmatic" UI layout. Of cause a simple Hello World application will not lead to a huge code change, how about a bigger change like building a calculator for example? A little changes in UI may lead to a huge change in back end programming coding.
To start using XML, you must copy and paste the following code.
More Information, may refer here under subtopic Upgrade the UI to an XML layout.
In the Eclipse Package Explorer, expand the
/res/layout/
folder and open main.xml
(once opened, you might need to click the "main.xml" tab at the bottom of the window to see the XML source). Replace the contents with the following XML:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello"/>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello"/>
Save the file,
Inside the
res/values/
folder, open strings.xml
. This is where you should save all default text strings for your user interface.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello, Android! I am a string resource!
<string name="app_name">Hello, Android
</resources>
<resources>
<string name="hello">Hello, Android! I am a string resource!
<string name="app_name">Hello, Android
</resources>
If you did some changes in the previous tutorial, here you need to change it back, you should see something like this.
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Now you should see something like this.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrKPj850Dz-hRktucIuVitrGT0FfV5qbrnqnTyBkb7PhjK2yrpAgn-R6uZiEYqWQMquoXDBOxGKiSuMxd11M-OZNt_WUQMAxf2w1rJEHEny0_2wnHAZx2fRDEoQIDCeHi3gR9ZHIF0bUg/s400/hello+world+display+2.jpg)
They is another things in R.java which you may refer to here. But I do not want to confuse myself and you, so maybe this time we will first skip this part, and maybe we will get back later when we need it.
Of course later we must have some more hands on to show we really understood.
if you are just copy and paste the code, but don't really know why, then you must continue with the exercise of Hello World.
Please drop me a comment if any question.
No comments:
Post a Comment