1.打开Eclipse, 选择 File >
New > Project.
2.选择 "Android Project" and click Next。
3.Fill in the project details with the
following values:
Project name: HelloAndroid
Application name: Hello, Android
Package name: com.example.helloandroid (or your own private
namespace)
Create Activity: HelloAndroid
Min SDK Version: 2
Click Finish.
4.这样一个工程就生成了,里面自动生成的源码如下:
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
修改为:
package com.android.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
5.运行
Select Run > Run.
Select "Android Application".
效果