Hello World!
TextViewに「Hello World」を表示させます。
1.新規プロジェクトの作成
まずは、新規プロジェクトを作成します。
eclipseでファイル→新規→Androidプロジェクトを選択。
プロジェクト名 |
→ HelloWorld |
アプリケーション名 |
→ HelloWorld |
パッケージ名 |
→ com.helloWorld |
CreateActivity |
→ HelloActivity |
Min SDK Version |
→ 4 |
それぞれの値を設定し、終了ボタンを押してプロジェクトを作成します。
2.TextViewを配置する
「Hello, World」を表示するためのTextViewをレイアウトに配置します。
HelloWorld/res/layout/main.xmlを開きます。
3.ソースコードを編集する
HelloWorld/src/com/helloWorld/helloActivity.javaを編集します。
package com.helloWorld;
import com.helloWorld.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class helloActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// ここから追加
TextView tv = (TextView) this.findViewById(R.id.TextView01);
tv.setText("Hello, World"); // TextViewへ文字を入れる
}
}
4.AndroidManifestを編集する
HelloWorld/AndroidManifest.xmlを編集します。
エミュレータでデバッグするための情報を追加。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.helloWorld"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".helloActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- 追加 -->
<uses-library android:name="android.test.runner" />
</application>
<uses-sdk android:minSdkVersion="4" />
<!-- 追加 -->
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.helloWorld"
android:label="@string/app_name" />
</manifest>
5.エミュレータで実行する。
終わり。
広告
最終更新:2010年07月20日 16:12