ダイアログがでるので、最低限Project名とPackage名を入力すれば、HelloWorldアプリが新規に作成されます。
ここでは、Project名は「SampleApp」、Package名は「jp.myapp.sample」としています。命名規則ですが、Android的な通例はProject名は先頭大文字、続きは小文字、2つ以上の単語をつなげるときは、アンダースコア(_)など間にいれない、Package名はすべて小文字、ドット(.)で2つ以上の単語が必須、といった感じです。このあたりは公式サンプルアプリやAPIの名前などを眺めて真似するのが良いと思います。
そのまま実行すれば下記のようなアプリが起動します。
作成されたProjectの中身をみるといろいろなファイルやフォルダが作成されていますが、まず見る必要のあるものは、
- srcフォルダにあるJavaソースコード
- res/drawable-xxxフォルダにあるアイコン画像ファイル
- res/layoutフォルダにあるレイアウトxmlファイル(main.xml)
- res/valuesフォルダにある文字列xmlファイル(strings.xml)
- AndroidManifest.xmlファイル
ソースコードはAndroidのActivityクラスを継承したSampleAppActivityクラスが1つ作成され、そのActivityクラスのonCreate()メソッドをoverrideして、setContentView()メソッドでlayoutフォルダにあるmain.xmlで定義された画面のレイアウトファイルを読み込んで画面表示しているだけです。
package jp.myapp.sample;
import android.app.Activity;
import android.os.Bundle;
public class SampleAppActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
main.xmlファイルをみるとLinearLayoutというレイアウトで、TextViewというView画面を配置し、strings.xmlで定義された文字列「hello」をテキスト表示するよう指示しています。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, SampleAppActivity!</string>
<string name="app_name">SampleApp</string>
</resources>
AndroidManifest.xmlはアプリに1つだけあるファイルで、アプリの設定が記述されています。中身はアイコン画像やアプリ名、最初に起動するActivityクラスなどが指定されています。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.myapp.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".SampleAppActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>









