å¤é¨ã©ã¤ãã©ãªã®ãããï¼
å¼ãç¶ãå¤é¨ã©ã¤ãã©ãªã®ãããï¼ã§ãã
ä»åã¯Androidã®å¤é¨ã©ã¤ãã©ãªã®ä½ãæ¹ã§ãã
ååã®å¾åã§ãAndroidSDKã®APIã使ãå¤é¨ã©ã¤ãã©ãªã®ä½ãæ¹æ¸ãã¾ããã
ä»åã¯ãªã½ã¼ã¹ã使ãå¤é¨ã©ã¤ãã©ãªã®ä½ãæ¹ã§ãã
å®å
¨ã«å¤é¨åããããã«ã¯å½éåãªãããæ¸ã¾ãã¦ããããã§ããã
æ§æ
- AndroidApp
- Androidã¢ããªããã¸ã§ã¯ã
- AndroidLib
- ã©ã¤ãã©ãªããã¸ã§ã¯ã
- AndroidAppã¯AndroidLibã®ã¯ã©ã¹ã®ã¡ã½ãããå¼ã³åºãã¾ã
- AndroidLibã¯èªèº«ã«å®ç¾©ããã¦ããæååãªã½ã¼ã¹ãè¿ãã¾ã
- AndroidAppã¯åãåã£ãæååãToastã§è¡¨ç¤ºãã¾ãã
ç°¡åãªã¢ããªã§ããã¼ã
AndroidLib
ã¾ãã¯AndroidLibããã¸ã§ã¯ããä½ãã¾ãã
New Project
Project Name:AndroidLib Build Target:Android 1.6 Application Name:AndroidLib Package Name:jp.tomorrowkey.android.androidlib Min SDK Version:4
Acitivtyã¯ä½ããªãã®ã§ãCreate Activityã®ãã§ãã¯ã¯å¤ãã¾ãã
Project Properties
is Libraryã®ãã§ãã¯ãå
¥ãã¾ãã
ããã®ãã§ãã¯ãå
¥ããã¨ã©ããå¤ãããã¨ããã¨
default.propertiesãã¡ã¤ã«ã«"android.library=true"ã¨ããæ°ããããããã£ãä½æããã¾ãã
AndroidManifest.xml
AndroidManifestãå¤æ´ãã¾ãã
applicationã¨ã¬ã¡ã³ããåé¤ãã¾ãã
ã©ã¤ãã©ãªãªã®ã§ã¢ããªåã¨ãã¢ã¤ã³ã³ã¨ãå¿
è¦ããã¾ããã
ãããããã¨æªãããããã§æ¶ãã¦ããã¹ãã§ãã
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="jp.tomorrowkey.android.androidlib" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="4" /> </manifest>
res/layout/main.xml
åé¤ãã¾ãã
使ãã¾ããã
res/values-ja/strings.xml
æ°ããä½æãã¾ãã
æ¥æ¬èªã®æååãªã½ã¼ã¹ã§ãã
ããã«ã¡ããææ¥!
res/values/string.xml
helloã¨ããé
ç®ãåé¤ãã¦ãgreetingã¨ããæååã足ãã¾ãã
æ¥æ¬èªä»¥å¤ã®æååãªã½ã¼ã¹ã§ãã
Hello Tomorrow!
AndroidApp
ç¶ãã¦AndroidAppãä½ãã¾ãã
New Project
ProjectName:AndroidApp Build Target:Android 1.6 Application Name:Android App Package:jp.tomorrowkey.android.androidapp Create Activity:MainActivity Min SDK Version:4
Project Properties
Add... -> AndroidLib -> OK
ã§ãããªæãã«ãªãã¨æãã¾ãã
ããã¾ã§çµãã£ããAndroidLibã®ããã¸ã§ã¯ããåç
§ãã§ãã¦ããã¯ããªãã§ãã
ãªãã¬ãã·ã¥ãã¦ãã¯ãªã¼ã³ãã¦ãAndroidAppããAndroidLibã®ã¯ã©ã¹ã¯åç
§ã§ããâ¦ã
ãããããªãã®ã§Eclipseãåèµ·åããã¨è¡¨ç¤ºãããããã«ãªãã¾ãã
/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/btnPushMe" android:text="push me" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
/src/jp.tomorrowkey.android.androidapp.MainActivity.java
package jp.tomorrowkey.android.androidapp; import jp.tomorrowkey.android.androidlib.Util; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener { private Button btnPushMe; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnPushMe = (Button) findViewById(R.id.btnPushMe); btnPushMe.setOnClickListener(this); } @Override public void onClick(View view) { int id = view.getId(); if (id == R.id.btnPushMe) { String greeting = Util.getGreeting(this); Toast.makeText(this, greeting, Toast.LENGTH_LONG).show(); } } }
ããã§
ãã¹ã¦å®æã§ãã
å®è¡ãã¦ã¿ã¾ãã
è¦ç¹/注æç¹
- ã©ã¤ãã©ãªããã¸ã§ã¯ãã¯ProjectPropertiesã®Androidã®is Libraryã«ãã§ãã¯ãå ¥ãã
- ã©ã¤ãã©ãªããã¸ã§ã¯ãã®AndroidManifest.xmlã®ã¢ããªåã¨ã¢ã¤ã³ã³åã¯åé¤ãã
- ã©ã¤ãã©ãªã使ãããã¸ã§ã¯ãå´ã¯ProjectPropertiesã®Androidã®ã©ã¤ãã©ãªã«ä½¿ç¨ããã©ã¤ãã©ãªã追å ãã
- 追å ããå¾ã¯Eclipseãåèµ·åãã*1
- ã©ã¤ãã©ãªã®ãªã½ã¼ã¹åã¨ã¢ããªå´ã®ãªã½ã¼ã¹åã¯ç°ãªãç©ã«ããæ¹ãç¡é£ã§ã
ã¡ãªã¿ã«
Androidã©ã¤ãã©ãªã追å ãããã¨ã®ããã¸ã§ã¯ãã¯ãã¾ã¾ã§ã«ã¯ãªãé¢ç½ãå½¢ã«ãªã£ã¦ã¾ãã
R.javaãäºã¤ãã£ãããã©ã¤ãã©ãªã®javaãã¡ã¤ã«ãè¦ãããã
ã¡ãªã¿ã«ããUtil.javaãå¤æ´ããã¨ã©ã¤ãã©ãªããã¸ã§ã¯ãã®Util.javaãæ´æ°ããããã
ã¨ãããã
ã¨ããããã§ããã¨ããå½¢ã§æ¸ãã¾ããã
ãã¨ã¯ä½ãã§ããã¨ããã©ãã注æç¹ã ã¨ãã¯èª°ããã¾ã¨ãã¦ãããããããªãããªã¼ï¼
ç¹ã«æ³¨æç¹ã¯å¤ãæ°ããã¾ãã
*1:ä½ãæ´æ°ããæ¹æ³ãããã°æãã¦ãã ãã