Dissecting HelloAndroid.java
- Activity
and View
package com.mytest;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this); // Construct a TextView UI
textView.setText("Hello, world!"); // Set text for TextView
setContentView(textView); // This Activity sets content to the TextView
}
}
An application could have one or more
Activity
. An Activity
is a single, focused thing that the user can do. Our Android Java class HelloAndroid
extends from the Activity
class, and overrides the onCreate()
method. The onCreate()
is a call-back method, which will be called by the Android System when the activity is first created.
A
View
is a drawable object (or UI component). We construct a TextView
(which is a subclass of View
), and set it to contain the String
"Hello, world". We then set the Activity
screen to this TextView
.
No comments :
Post a Comment
Your Comment and Question will help to make this blog better...