Android¥¢¥×¥ê¤ò³«È¯¤¹¤ë¤¿¤á¤Î´ðÁäò¤Þ¤È¤á¤Æ¤¢¤ê¤Þ¤¹¡£


²èÌ̥쥤¥¢¥¦¥È¤Îµ­½Ò

¥á¥¤¥ó²èÌ̤Υ쥤¥¢¥¦¥ÈÄêµÁ¥Õ¥¡¥¤¥ë¡Êres/layout/main.xml¡Ë¤ÎÊÔ½¸

<?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">
    <Button android:id="@+id/Button1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="¥À¥¤¥¢¥é¡¼µ¯Æ°" />
<!-- -------------------------------------------------------------------------------- -->
<!-- ¢­¤³¤³¤«¤é -->
<!-- -------------------------------------------------------------------------------- -->
    <Button android:id="@+id/Button2"                              
            android:layout_width="fill_parent"                      
            android:layout_height="wrap_content"                   
            android:text="¥Ö¥é¥¦¥¶µ¯Æ°" />
<!-- -------------------------------------------------------------------------------- -->
<!-- ¢¬¤³¤³¤Þ¤Ç -->
<!-- -------------------------------------------------------------------------------- -->
    <Button android:id="@+id/Button3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="²èÌÌÁ«°Ü" />
</LinearLayout>

²òÀâ

¡¦android:layout_width:  ²£¤ÎŤµ
¡¦android:layout_height: ½Ä¤ÎŤµ
¡¦fill_parent: ¿Æ¤ÎŤµ¤Ë¹ç¤ï¤»¤ë
  => Android2.2¤è¤ê¡¢match_parent¤ËÊѹ¹
     (°ú¤­Â³¤­fill_parent¤Ï»ÈÍѲÄǽ)
¡¦wrap_content: ÆâÍƤÎŤµ¤Ë¹ç¤ï¤»¤ë

¡¦¥ì¥¤¥¢¥¦¥ÈXML¤«¤é¥ê¥½¡¼¥¹¤ò»²¾È¤¹¤ëÊýË¡: @¥ê¥½¡¼¥¹¤Î¥¿¥¤¥×/¥ê¥½¡¼¥¹Ì¾
  => ¥ê¥½¡¼¥¹¤Î¥¿¥¤¥×
     string: ʸ»úÎó
     color:  ¿§
     dimen:  ʸ»ú¤ÎÂ礭¤µ

¥Ö¥é¥¦¥¶µ¯Æ°¥Ü¥¿¥ó¤ò²¡²¼¤·¤¿»þ¤Î½èÍý¤òÄɲÃ

public class MainActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		// ¥À¥¤¥¢¥é¡¼¥Ü¥¿¥ó¤ò²¡²¼¤·¤¿¤È¤­
		Button dialButton = (Button) findViewById(R.id.Button1);
		dialButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(Intent.ACTION_DIAL);
				// ÅÅÏÃÈÖ¹æ¤òÀßÄê
				Uri uri = Uri.parse("tel:09012345678");
				intent.setData(uri);
				startActivity(intent);
			}
		});

		// ¥Ö¥é¥¦¥¶¡¼¥Ü¥¿¥ó¤ò²¡²¼¤·¤¿¤È¤­
//--------------------------------------------------------------------------------
//¢­¤³¤³¤«¤é
//--------------------------------------------------------------------------------
		Button browzerButton = (Button) findViewById(R.id.Button2);
		browzerButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(Intent.ACTION_VIEW);
				Uri uri = Uri.parse("http://ecnavi.jp/");
				intent.setData(uri);
				startActivity(intent);
			}
		});
//--------------------------------------------------------------------------------
//¢¬¤³¤³¤Þ¤Ç
//--------------------------------------------------------------------------------
		// ²èÌÌÁ«°Ü¥Ü¥¿¥ó¤ò²¡²¼¤·¤¿¤È¤­
	}
}

²òÀâ

setContentView
¥ì¥¤¥¢¥¦¥ÈXML¤ÎÃæ¤Ëµ­½Ò¤µ¤ì¤¿²èÌ̥쥤¥¢¥¦¥È¤ò¥»¥Ã¥È¤¹¤ë¤È¤¤¤¦°ÕÌ£¤Ç¤¹¡£

²èÌ̤òɽ¼¨¤¹¤ë¤¿¤á¤Ë¤Ï¡¢É¬¤º¥ì¥¤¥¢¥¦¥ÈXML¤¬É¬¿Ü¡¢¤È¤¤¤¦¤ï¤±¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£
¥ì¥¤¥¢¥¦¥ÈXML¤ò»È¤ï¤Ê¤¤¤Ç¡¢Java¤À¤±¤ò»È¤Ã¤Æ²èÌ̥쥤¥¢¥¦¥È¤òµ­½Ò¤¹¤ë¤³¤È¤â²Äǽ¤Ç¤¹¡£
Î㤨¤Ð¡¢¤³¤Î¤è¤¦¤Ê´¶¤¸¤Ç¤¹¡£

Button bt = new Button(this);
bt.setText("¥Ö¥é¥¦¥¶µ¯Æ°");
setContentView(bt);
findViewById
¥¦¥£¥¸¥§¥Ã¥È¤ò¼èÆÀ¤·¤¿¤¤¤È¤­¤Ï¡¢Activity¤¬»ý¤Ã¤Æ¤¤¤ë

View findViewById(int id)

¤È¤¤¤¦¥á¥½¥Ã¥É¤ò»È¤¤¤Þ¤¹¡£

°ú¿ô¤È¤·¤Æ¥¦¥£¥¸¥§¥Ã¥È¤ÎID¤ò¼õ¤±¼è¤Ã¤Æ
¤½¤ÎID¤Ë¤è¤Ã¤Æ¼±Ê̤µ¤ì¤ë¥¦¥£¥¸¥§¥Ã¥È¤òÌá¤êÃͤȤ·¤ÆÊÖ¤·¤Þ¤¹¡£
¤¿¤À¤·¡¢Ìá¤êÃͤη¿¤Ï¡¢¥¦¥£¥¸¥§¥Ã¥È¤Î¼ïÎऴ¤È¤Î¥¯¥é¥¹¤Ç¤Ï¤Ê¤¯¤Æ¡¢

android.view.View

¤È¤¤¤¦¥¹¡¼¥Ñ¡¼¥¯¥é¥¹¤Ç¤¹¤Î¤Ç¡¢¥­¥ã¥¹¥È¤¹¤ë¤³¤È¤¬É¬Íפˤʤê¤Þ¤¹¡£

Îã)
¥Ü¥¿¥ó¤Î¥¯¥é¥¹Ì¾¤Ï

android.widget.Button

¤Ê¤Î¤Ç

Button dialButton = (Button) findViewById(R.id.Button1);

¤È½ñ¤¯¤³¤È¤Ë¤è¤Ã¤Æ¡¢dialButton¤È¤¤¤¦ÊÑ¿ô¤ËÀßÄꤷ¤Þ¤¹¡£
¥¤¥Ù¥ó¥È¥ê¥¹¥Ê¡¼¤È¤Ï
¥æ¡¼¥¶¡¼¤Ë¤è¤ëÁàºî¤Ê¤É¤Ë¤è¤Ã¤ÆÀ¸¤¸¤ë¡¢¥Ü¥¿¥ó¤¬¥¯¥ê¥Ã¥¯¤µ¤ì¤¿¤È¤¤¤¦¤è¤¦¤Ê½ÐÍè»ö¤Ï¡¢¡Ö¥¤¥Ù¥ó¥È¡× ¤È¸Æ¤Ð¤ì¤Þ¤¹¡£
¥¦¥£¥¸¥§¥Ã¥È¾å¤Ç¥¤¥Ù¥ó¥È¤¬È¯À¸¤·¤¿¤È¤­¤Ë¡¢¤½¤Î¥¤¥Ù¥ó¥È¤Ë±þ¤¸¤¿½èÍý¤ò¤¹¤ë¤¿¤á¤Ë¤Ï¡¢
¡Ö¥¤¥Ù¥ó¥È¥ê¥¹¥Ê¡¼¡×¤È¸Æ¤Ð¤ì¤ë¥ª¥Ö¥¸¥§¥¯¥È¤òºî¤Ã¤Æ¡¢¥¦¥£¥¸¥§¥Ã¥È¤ËÀßÄꤷ¤Æ¤ª¤¯É¬Íפ¬¤¢¤ê¤Þ¤¹¡£

¥¤¥Ù¥ó¥È¥ê¥¹¥Ê¡¼¤Ï¡¢¡Ö¥¤¥Ù¥ó¥È¤¬È¯À¸¤·¤¿¤È¤­¤Ë¸Æ¤Ó½Ð¤µ¤ì¤ë¥á¥½¥Ã¥É¤ò»ý¤Ã¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¡×¤Î¤³¤È¤Ç¤¹¡£
¥¤¥Ù¥ó¥È¥ê¥¹¥Ê¡¼¤Îºî¤êÊý
¥¤¥Ù¥ó¥È¥ê¥¹¥Ê¡¼¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤·¤¿¥¯¥é¥¹¤òÄêµÁ¤·¤Æ¡¢¤½¤Î¥¯¥é¥¹¤Î¥¤¥ó¥¹¥¿¥ó¥¹¤òÀ¸À®¤·¤Þ¤¹¡£
¥¯¥ê¥Ã¥¯¤µ¤ì¤¿¤È¤¤¤¦¥¤¥Ù¥ó¥È¤ò½èÍý¤¹¤ë¥¤¥Ù¥ó¥È¥ê¥¹¥Ê¡¼¤Ï

android.view.View.OnClickListener

¤È¤¤¤¦¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤·¤Æºî¤ê¤Þ¤¹¡£
¤³¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤¬ÄêµÁ¤·¤Æ¤¤¤ë¤Î¤Ï

void onClick(View v)

¤È¤¤¤¦¥á¥½¥Ã¥É¤Ç¤¹¡£
¥¦¥£¥¸¥§¥Ã¥È¤¬¥¯¥ê¥Ã¥¯¤µ¤ì¤¿¤È¤¤¤¦¥¤¥Ù¥ó¥È¤¬È¯À¸¤¹¤ë¤È¡¢
¤³¤Î¥á¥½¥Ã¥É¤¬¸Æ¤Ó½Ð¤µ¤ì¤Æ¡¢¥¯¥ê¥Ã¥¯¤µ¤ì¤¿¥¦¥£¥¸¥§¥Ã¥È¤¬°ú¿ô¤È¤·¤ÆÅϤµ¤ì¤Þ¤¹¡£

¥µ¥Ö²èÌ̤ÎÄɲÃ

SubActivity¥¯¥é¥¹¤ÎÊÔ½¸

public class SubActivity extends Activity {
//--------------------------------------------------------------------------------
//¢­¤³¤³¤«¤é
//--------------------------------------------------------------------------------
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sub);
	}
//--------------------------------------------------------------------------------
//¢¬¤³¤³¤Þ¤Ç
//--------------------------------------------------------------------------------
}

¥µ¥Ö²èÌ̤Υ쥤¥¢¥¦¥È¥Õ¥£¥ë¤òÀ¸À®

¥µ¥Ö²èÌ̤Υ쥤¥¢¥¦¥ÈÄêµÁ¥Õ¥¡¥¤¥ë¤ÎÊÔ½¸

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
<!-- -------------------------------------------------------------------------------- -->
<!-- ¢­¤³¤³¤«¤é -->
<!-- -------------------------------------------------------------------------------- -->
<TextView
    android:id="@+id/textView01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="¥µ¥Ö¥¢¥¯¥Æ¥£¥Ó¥Æ¥£²èÌ̤ËÁ«°Ü¤·¤Þ¤·¤¿" />
<!-- -------------------------------------------------------------------------------- -->
<!-- ¢¬¤³¤³¤Þ¤Ç -->
<!-- -------------------------------------------------------------------------------- -->
</LinearLayout>

¥Þ¥Ë¥å¥Õ¥§¥¹¥È¥Õ¥¡¥¤¥ë¤ÎÊÔ½¸

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="jp.co.test"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
<!-- -------------------------------------------------------------------------------- -->
<!-- ¢­¤³¤³¤«¤é -->
<!-- -------------------------------------------------------------------------------- -->
        <activity android:name=".SubActivity"
                  android:label="@string/sub_activity_name">
        </activity>
<!-- -------------------------------------------------------------------------------- -->
<!-- ¢¬¤³¤³¤Þ¤Ç -->
<!-- -------------------------------------------------------------------------------- -->
    </application>
</manifest>

²òÀâ

package
¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥Ñ¥Ã¥±¡¼¥¸Ì¾¤ò´°Á´½¤¾þ̾¤Ç»ØÄꤷ¤Þ¤¹¡£
¤³¤ì¤Ï°Ê²¼¤ÎÍÑÅÓ¤ÇÍøÍѤµ¤ì¤Þ¤¹¡£

¢£´ð½à¥Ñ¥Ã¥±¡¼¥¸Ì¾
¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Î¥¯¥é¥¹Ì¾¤Ê¤É¡¢¤³¤Î¥Ñ¥Ã¥±¡¼¥¸¤«¤é¤ÎÁêÂХѥ¹Ì¾¤Çµ­½Ò¤Ç¤­¤Þ¤¹¡£

¢£¥×¥í¥»¥¹Ì¾
¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¼Â¹Ô¤¹¤ë¤È¤­¤Î¥Ç¥Õ¥©¥ë¥È¥×¥í¥»¥¹Ì¾¤È¤·¤Æ»ÈÍѤµ¤ì¤Þ¤¹¡£
uses-sdk
¤³¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¤É¤ÎAndroid SDK¤ÇÆ°ºî²Äǽ¤Ê¤Î¤«¤òÄêµÁ¤·¤Þ¤¹¡£

¢£android:minSdkVersion
Æ°ºî¤ËɬÍפÊAPI Level¤òÀ°¿ô¤Ç»ØÄꤷ¤Þ¤¹¡£

¢£android:targetSdkVersion
¤³¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬¥¿¡¼¥²¥Ã¥È¤È¤·¤Æ¤¤¤ëAPI Level¤òÀ°¿ô¤Ç»ØÄꤷ¤Þ¤¹¡£

¢£android:maxSdkVersion
¤³¤Î¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤¬Æ°ºî¤¹¤ëºÇÂç¤ÎAPI Level¤òÀ°¿ô¤Ç»ØÄꤷ¤Þ¤¹¡£
application
¢£android:icon
¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥Ç¥Õ¥©¥ë¥È¥¢¥¤¥³¥ó¤ò»ØÄꤷ¤Þ¤¹¡£
¤³¤ì¤Ï¥³¥ó¥Ý¡¼¥Í¥ó¥Èñ°Ì¤Ç¤âÄêµÁ¤Ç¤­¤Þ¤¹¡£

¢£android:label
¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î¥é¥Ù¥ë̾¾Î¤ò»ØÄꤷ¤Þ¤¹¡£
activity
µö²Ä¤·¤¿¤¤Activity¤Î¥¯¥é¥¹Ì¾¤ò»ØÄꤷ¤Þ¤¹¡£
Android¤Ï¡¢¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï¡¢Á´¤Æ¤ÎActivity¤Îµ¯Æ°¤¬µñÈݤµ¤ì¤Æ¤¤¤Þ¤¹¡£
¤³¤³¤Ëµ­½Ò¤·¤¿Activity¥¯¥é¥¹¤À¤±¤¬µö²Ä¤µ¤ì¤ë¤È¤¤¤¦»ö¤Ç¤¹¡£
intent-filter
Activity¤Îµ¯Æ°¾ò·ï¡Ê¥Õ¥£¥ë¥¿¡Ë¤òÀßÄꤷ¤Þ¤¹¡£
¤³¤ÎÃæ¤Ë¡¢action, category, data¤Î»ÒÍ×ÁǤòÄêµÁ¤·¤Þ¤¹¡£

¢£action
¥Õ¥£¥ë¥¿¥ê¥ó¥°¤¹¤ë¥¢¥¯¥·¥ç¥ó¤òÄêµÁ¤·¤Þ¤¹¡£
¥¢¥¯¥·¥ç¥ó̾¤òÄêµÁ¤·¤Þ¤¹¡£Intent ¥¯¥é¥¹¤ËÄêµÁ¤µ¤ì¤¿Äê¿ô¤¬»È¤¨¤Þ¤¹¡£

¢£category
¥Õ¥£¥ë¥¿¥ê¥ó¥°¤¹¤ë¥«¥Æ¥´¥ê¤òÄêµÁ¤·¤Þ¤¹¡£
¥«¥Æ¥´¥ê̾¤òÄêµÁ¤·¤Þ¤¹¡£Intent ¥¯¥é¥¹¤ËÄêµÁ¤µ¤ì¤¿Äê¿ô¤¬»È¤¨¤Þ¤¹¡£

¢£data
¥Õ¥£¥ë¥¿¥ê¥ó¥°¤¹¤ëURI¤òÄêµÁ¤·¤Þ¤¹¡£
URI¤Ï¡¢¡Öscheme://host:port/path¡×¤Ç¹½À®¤µ¤ì¤Þ¤¹¡£
°Ê²¼¤Î°À­¤¬»ÈÍѲÄǽ¤Ç¤¹¡£

android:host
¥Û¥¹¥È̾¤ò»ØÄꤷ¤Þ¤¹¡£
¤³¤ì¤Ï android:scheme ¤¬ÄêµÁ¤µ¤ì¤¿¾ìÌ̤ǤΤßÍ­¸ú¤Ç¤¹¡£

android:mimeType
MIME Type ¤ò»ØÄꤷ¤Þ¤¹¡£* ¤Ë¤è¤ë¥ï¥¤¥ë¥É¥«¡¼¥É¤¬»È¤¨¤Þ¤¹¡£

android:path
¥Ñ¥¹¤ò»ØÄꤷ¤Þ¤¹¡Ê´°Á´°ìÃפȤʤê¤Þ¤¹¡Ë¡£

android:pathPrefix
¥Ñ¥¹¤ÎÀèƬÉôʬ¤ò»ØÄꤷ¤Þ¤¹¡£

android:pathPattern
¥Ñ¥¹¤ò»ØÄꤷ¤Þ¤¹¡Ê´°Á´°ìÃסˡ£* ¤Ë¤è¤ë¥ï¥¤¥ë¥É¥«¡¼¥É¤¬»È¤¨¤Þ¤¹¡£

android:
¥Ý¡¼¥ÈÈÖ¹æ¤ò»ØÄꤷ¤Þ¤¹¡£ 
¤³¤ì¤Ï android:scheme ¤ª¤è¤Ó android:host ¤¬ÄêµÁ¤µ¤ì¤¿¾ìÌ̤ǤΤßÍ­¸ú¤Ç¤¹¡£

android:scheme
¥¹¥­¡¼¥Þ¤ò»ØÄꤷ¤Þ¤¹¡£
"http" ¤Î¤è¤¦¤Ë¡¢¥³¥í¥ó¤ÏÉÕ¤±¤º¤Ë»ØÄꤷ¤Þ¤¹¡£
¤³¤ÎÃͤÏɬ¤º°ì¤Ä°Ê¾å»ØÄꤷ¤Æ²¼¤µ¤¤¡£¤½¤¦¤Ç¤Ê¤¤¤È¡¢Â¾¤Î»ØÄ꤬ͭ¸ú¤Ë¤Ê¤ê¤Þ¤»¤ó¡£

¥á¥¤¥ó²èÌ̤ÎActivity¥¯¥é¥¹¤Î½¤Àµ

public class MainActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	         //////  Ãæά  ////////

		// ¥Ö¥é¥¦¥¶¡¼¥Ü¥¿¥ó¤ò²¡²¼¤·¤¿¤È¤­
		Button browzerButton = (Button) findViewById(R.id.Button2);
		browzerButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(Intent.ACTION_VIEW);
				Uri uri = Uri.parse("http://ecnavi.jp/");
				intent.setData(uri);
				startActivity(intent);
			}
		});
//--------------------------------------------------------------------------------
//¢­¤³¤³¤«¤é
//--------------------------------------------------------------------------------
		// ²èÌÌÁ«°Ü¥Ü¥¿¥ó¤ò²¡²¼¤·¤¿¤È¤­
		Button activityButton = (Button) findViewById(R.id.Button3);
		activityButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this, SubActivity.class);
				startActivity(intent);
			}
		});
//--------------------------------------------------------------------------------
//¢¬¤³¤³¤Þ¤Ç
//-------------------------------------------------------------------------------
	}
}

¥³¥á¥ó¥È¤ò¤«¤¯


¡Öhttp://¡×¤ò´Þ¤àÅê¹Æ¤Ï¶Ø»ß¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ÍøÍѵ¬Ìó¤ò¤´³Îǧ¤Î¤¦¤¨¤´µ­Æþ²¼¤µ¤¤

´ÉÍý¿Í/Éû´ÉÍý¿Í¤Î¤ßÊÔ½¸¤Ç¤­¤Þ¤¹