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

Step1 »öÁ°½àÈ÷1

¼¡¤Î¥×¥í¥¸¥§¥¯¥È¤òºîÀ®¤·¤Æ¤¯¤À¤µ¤¤¡£
¹àÌÜ̾ÀßÄêÃÍ
¥×¥í¥¸¥§¥¯¥È̾janken
¥Ó¥ë¥É¥¿¡¼¥²¥Ã¥ÈAndroid 2.2
¥¢¥×¥ê¥±¡¼¥·¥ç¥ó̾¤¸¤ã¤ó¤±¤ó¥²¡¼¥à
¥Ñ¥Ã¥±¡¼¥¸Ì¾jp.co.example.janken
¥¢¥¯¥Æ¥£¥Ó¥Æ¥£¤ÎºîÀ®mainActivity
ºÇ¾®SDK¥Ð¡¼¥¸¥ç¥ó8

Step2 »öÁ°½àÈ÷2

»öÁ°¤Ë¥À¥¦¥ó¥í¡¼¥É¤·¤Æ¤ª¤¤¤¿²èÁü¤ò¡¢res/drawable-nodpi¥Õ¥©¥ë¥À¡¼¤Ë¥³¥Ô¡¼¤·¤Æ¤¯¤À¤µ¤¤¡£
¢¨drawable-nodpi¥Õ¥©¥ë¥À¡¼¤¬Â¸ºß¤·¤Ê¤¤¾ì¹ç¡§ res¥Õ¥©¥ë¥À¡¼¤ò±¦¥¯¥ê¥Ã¥¯¤·¡¢¿·µ¬¢ª¥Õ¥©¥ë¥À¡¼¤è¤êºîÀ®

°Ê¾å¤Ç¡¢»öÁ°½àÈ÷¤Ï´°Î»¤Ç¤¹¡£´°À®·Á¤Ï¡¢¤³¤ó¤Ê·Á¤Ç¤¹¡£

Step3 ¥ì¥¤¥¢¥¦¥ÈºîÀ®

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="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF">
<TextView  
    android:id="@+id/message"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dip"
    android:textColor="#000000"
    android:textSize="20sp"
    android:text="¤¸¤ã¤ó¤±¤ó¡¦¡¦¡¦" />
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button 
        android:id="@+id/other_gu"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:text="¤°¡¼"
        android:layout_weight="1" />
    <Button 
        android:id="@+id/other_choki"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:text="¤Á¤ç¤­"
        android:layout_weight="1" />
    <Button 
        android:id="@+id/other_pa"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:text="¤Ñ¡¼"
        android:layout_weight="1" />
 </LinearLayout>
<TextView  
    android:id="@+id/result"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center"
    android:layout_marginTop="30dip"
    android:layout_marginBottom="30dip"
    android:textColor="#000000"
    android:textSize="20sp"
    android:text="·ë²Ì¤òɽ¼¨" />
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button 
        android:id="@+id/my_gu"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:text="¤°¡¼"
        android:layout_weight="1" />
    <Button 
        android:id="@+id/my_choki"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:text="¤Á¤ç¤­"
        android:layout_weight="1" />
    <Button 
        android:id="@+id/my_pa"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:text="¤Ñ¡¼"
        android:layout_weight="1" />
 </LinearLayout>
 <Button 
     android:id="@+id/retry"
     android:layout_width="200dip"
     android:layout_height="wrap_content"
     android:layout_marginTop="50dip"
     android:layout_gravity="center"
     android:text="¤â¤¦°ìÅÙ" />
 </LinearLayout>
¼Â¹Ô¤·¡¢¼¡¤Î¤è¤¦¤Ëɽ¼¨¤µ¤ì¤Þ¤·¤¿¤«¡£¡Ê¾åÃÊ¡§Áê¼ê¤Î¼ê¡¢²¼ÃÊ¡§¼«Ê¬¤Î¼ê¡Ë

Step4

³Æ¥Ü¥¿¥ó¤ò¥×¥í¥°¥é¥à¤«¤éÀ©¸æ¤¹¤ë¤¿¤á¤Î½èÍý¤òµ­½Ò¤·¤Þ¤¹¡£
res/jp.co.example.janken/MainActivity.java¤ò¼¡¤Î¤è¤¦¤Ë½ñ¤­´¹¤¨¤Æ¤¯¤À¤µ¤¤¡£
public class MainActivity extends Activity implements OnClickListener {
	private Button otherGuBtn;
	private Button otherChokiBtn;
	private Button otherPaBtn;
	private Button myGuBtn;
	private Button myChokiBtn;
	private Button myPaBtn;
	private Button retryBtn;
	private TextView message;
	private TextView result;
	private static final int GU = 0;
	private static final int CHOKI = 1;
	private static final int PA = 2;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		// ¼«Ê¬¤Î¼ê
		myGuBtn = (Button) findViewById(R.id.my_gu);
		myChokiBtn = (Button) findViewById(R.id.my_choki);
		myPaBtn = (Button) findViewById(R.id.my_pa);
		// Áê¼ê¤Î¼ê
		otherGuBtn = (Button) findViewById(R.id.other_gu);
		otherChokiBtn = (Button) findViewById(R.id.other_choki);
		otherPaBtn = (Button) findViewById(R.id.other_pa);
		// ¼«Ê¬¤Î¼ê¤Ë¥¤¥Ù¥ó¥È¥ê¥¹¥Ê¡¼¤ò¥»¥Ã¥È
		myGuBtn.setOnClickListener(this);
		myChokiBtn.setOnClickListener(this);
		myPaBtn.setOnClickListener(this);

		result = (TextView) findViewById(R.id.result);
		message = (TextView) findViewById(R.id.message);
		// ¥ê¥È¥é¥¤¥Ü¥¿¥ó
		retryBtn = (Button) findViewById(R.id.retry);
		retryBtn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				initView();
			}
		});
		// ¥Ó¥å¡¼¤Î½é´ü²½
		initView();
	}

	public void initView() {
		message.setText("¤¸¤ã¤ó¤±¤ó¡¦¡¦¡¦");
		result.setText(null);
		// ¼«Ê¬¤Î¼ê¤òÍøÍѲÄǽ¤Ë¤¹¤ë
		myGuBtn.setEnabled(true);
		myChokiBtn.setEnabled(true);
		myPaBtn.setEnabled(true);
		myGuBtn.setClickable(true);
		myChokiBtn.setClickable(true);
		myPaBtn.setClickable(true);
		// Áê¼ê¤Î¼ê¤ò¥¯¥ê¥Ã¥¯¤Ç¤­¤Ê¤¤¤è¤¦¤Ë¤¹¤ë
		otherGuBtn.setEnabled(true);
		otherChokiBtn.setEnabled(true);
		otherPaBtn.setEnabled(true);
		otherGuBtn.setClickable(false);
		otherChokiBtn.setClickable(false);
		otherPaBtn.setClickable(false);
		// ¥ê¥È¥é¥¤¥Ü¥¿¥ó¤òÈóɽ¼¨¤Ë¤¹¤ë
		retryBtn.setVisibility(View.GONE);
	}
}
importÀë¸À¤Î¥¤¥ó¥Ý¡¼¥È¤ò˺¤ì¤º¤Ë(windows: ctrl + shift + o, mac: command + shift + o)

Step5

¤¸¤ã¤ó¤±¤ó¤ò¤¹¤ë¤¿¤á¤Ë¡¢¼«Ê¬¤Î¼ê¤Î¥Ü¥¿¥ó¤ò²¡²¼¤·¤¿ºÝ¤Î½èÍý¤òÄɲä·¤Þ¤¹¡£
res/jp.co.example.janken/MainActivity.java¤Ë¡¢¼¡¤òÄɵ­¤·¤Æ¤¯¤À¤µ¤¤¡£
@Override
public void onClick(View v) {
	// ¥á¥Ã¥»¡¼¥¸¥é¥Ù¥ë¤ÎÊѹ¹
	message.setText("¤¸¤ã¤ó¤±¤ó¡¦¡¦¡¦¤Ý¤ó");
	// ¼«Ê¬¤Î¼ê¤ò¥¯¥ê¥Ã¥¯¤Ç¤­¤Ê¤¤¤è¤¦¤Ë¤¹¤ë
	myGuBtn.setEnabled(true);
	myChokiBtn.setEnabled(true);
	myPaBtn.setEnabled(true);
	myGuBtn.setClickable(false);
	myChokiBtn.setClickable(false);
	myPaBtn.setClickable(false);
	// ¥ê¥È¥é¥¤¥Ü¥¿¥ó¤òɽ¼¨¤¹¤ë
	retryBtn.setVisibility(View.VISIBLE);
        // ¼«Ê¬¤Î¼ê¤Îɽ¼¨¾õÂÖ¤òÊѹ¹
	myImage(v.getId());
        // Áê¼ê¤Î¼ê¤òµá¤á¡¢É½¼¨¾õÂÖ¤òÊѹ¹
	int other = getResult();
	otherImage(other);

	int id = v.getId();
	switch (other) {
	case GU:
		switch (id) {
		case R.id.my_gu:
			aiko();
			break;
		case R.id.my_choki:
			loose();
			break;
		case R.id.my_pa:
			win();
			break;
		}
		break;
	case CHOKI:
		switch (id) {
		case R.id.my_gu:
			win();
			break;
		case R.id.my_choki:
			aiko();
			break;
		case R.id.my_pa:
			loose();
			break;
		}
		break;
	case PA:
		switch (id) {
		case R.id.my_gu:
			loose();
			break;
		case R.id.my_choki:
			win();
			break;
		case R.id.my_pa:
			aiko();
			break;
		}
		break;
	}
}

// ¾¡¤Ã¤¿¾ì¹ç¤Î½èÍý
public void win() {
	result.setText("¤¢¤Ê¤¿¤Î¾¡¤Á");
}

// É餱¤¿¾ì¹ç¤Î½èÍý
public void loose() {
	result.setText("¤¢¤Ê¤¿¤ÎÉ餱");
}

// ¤¢¤¤¤³¤Î¾ì¹ç¤Î½èÍý
public void aiko() {
	myGuBtn.setEnabled(true);
	myChokiBtn.setEnabled(true);
	myPaBtn.setEnabled(true);
	myGuBtn.setClickable(true);
	myChokiBtn.setClickable(true);
	myPaBtn.setClickable(true);
	result.setText("¤¢¤¤¤³¤Ç¡¦¡¦¡¦");
	retryBtn.setVisibility(View.GONE);
}

// Áê¼ê¤Î¼ê¤ò·èÄê
public int getResult() {
	long seed = System.currentTimeMillis();
	Random rnd = new Random(seed);
	return rnd.nextInt(3);
}

Step6

¼«Ê¬¤Î¼ê¤Ë¤è¤Ã¤Æ¥Ü¥¿¥ó¤Îɽ¼¨¾õÂÖ¤òÊѹ¹¤¹¤ë½èÍý¤òÄɲä·¤Þ¤¹¡£
res/jp.co.example.janken/MainActivity.java¤Ë¡¢¼¡¤òÄɵ­¤·¤Æ¤¯¤À¤µ¤¤¡£
public void myImage(int id) {
	switch (id) {
	case R.id.my_gu:
		myGuBtn.setEnabled(true);
		myChokiBtn.setEnabled(false);
		myPaBtn.setEnabled(false);
		break;
	case R.id.my_choki:
		myGuBtn.setEnabled(false);
		myChokiBtn.setEnabled(true);
		myPaBtn.setEnabled(false);
		break;
	case R.id.my_pa:
		myGuBtn.setEnabled(false);
		myChokiBtn.setEnabled(false);
		myPaBtn.setEnabled(true);
		break;
	}
}

Step7

Áê¼ê¤Î¼ê¤Ë¤è¤Ã¤Æ¥Ü¥¿¥ó¤Îɽ¼¨¾õÂÖ¤òÊѹ¹¤¹¤ë½èÍý¤òÄɲä·¤Þ¤¹¡£
res/jp.co.example.janken/MainActivity.java¤Ë¡¢¼¡¤òÄɵ­¤·¤Æ¤¯¤À¤µ¤¤¡£
public void otherImage(int other) {
	switch (other) {
	case GU:
		otherGuBtn.setEnabled(true);
		otherChokiBtn.setEnabled(false);
		otherPaBtn.setEnabled(false);
		break;
	case CHOKI:
		otherGuBtn.setEnabled(false);
		otherChokiBtn.setEnabled(true);
		otherPaBtn.setEnabled(false);
		break;
	case PA:
		otherGuBtn.setEnabled(false);
		otherChokiBtn.setEnabled(false);
		otherPaBtn.setEnabled(true);
		break;
	}
}

Step8

¼Â¹Ô¤·¡¢¥×¥í¥°¥é¥à¤ÎÆ°ºî¤ò³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£
ÌäÂê¤Ê¤±¤ì¤Ð¡¢¼¡¤Î¥¹¥Æ¥Ã¥×¡Ê¥Ü¥¿¥ó¤ò²èÁü¤ËÊѹ¹¡Ë¤Ø¿Ê¤ó¤Ç¤¯¤À¤µ¤¤¡£

¤³¤Î¥Ú¡¼¥¸¤Ø¤Î¥³¥á¥ó¥È

3R40PK <a href="http://tqmppeqcwbup.com/">tqmppeqcwbup</a>, [url=http://okwfyeffzppg.com/]okwfyeffzppg[/url], [link=http://wcsouetumfez.com/]wcsouetumfez[/link], http://cvlmpmqwcewa.com/

0
Posted by ekkacicagk 2013ǯ11·î14Æü(ÌÚ) 14:01:19 ÊÖ¿®

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


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

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

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