±âº»ÀûÀ¸·Î ÃÊ·Ï»ö À̹ÌÁö¿Í Radio ¹öÆ° 3°³°¡ º¸À̵µ·Ï ·¹À̾ƿôÀ» Àâ¾Ò½À´Ï´Ù.
±×·±ÈÄ¿¡ ¹öÆ° º¯°æ½Ã À̹ÌÁö »öÀÌ º¯°æ µÇµµ·Ï ÇغýÀ´Ï´Ù. ¤»¤»
// HelloAppActivity.java
package com.home;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RadioGroup;
public class HelloAppActivity extends Activity
implements RadioGroup.OnCheckedChangeListener
{
/** Called when the activity is first created. */
RadioGroup orientation;
ImageView img;
Drawable defaultImg;
Drawable blueImg;
Drawable redImg;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
img = (ImageView)findViewById(R.id.imageView1);
// ÀÌ ºÎºÐÀ» ¸ô¶ó¼ ¾öû Çì¸Ë³×¿è
defaultImg = getResources().getDrawable(R.drawable.android_icon_125g);
blueImg = getResources().getDrawable(R.drawable.android_icon_125b);
redImg = getResources().getDrawable(R.drawable.android_icon_125r);
orientation = (RadioGroup)findViewById(R.id.radioGroup1);
orientation.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(RadioGroup group, int checkedId)
{
if(group == orientation)
{
switch(checkedId)
{
case R.id.radio0:
img.setImageDrawable(defaultImg);
break;
case R.id.radio1:
img.setImageDrawable(blueImg);
break;
case R.id.radio2:
img.setImageDrawable(redImg);
break;
}
}
}
}
// 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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Radio Button ¼±ÅÃÇϼ¼¿ä !!" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/android_icon_125g" />
<RadioGroup
android:id="@+id/radioGroup1"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#FF00FF00"
android:text="Green" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FF0000FF"
android:text="Blue" />
<RadioButton
android:id="@+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFF0000"
android:text="Red" />
</RadioGroup>
</LinearLayout>