¼±ÅûóÀÚ¿¡ ´ëÇؼ ¾Ë¾Æº¸ÀÚ. À©µµ¿ìÁî API¿¡¼´Â üũ ¹Ú½º·Î ºÎ¸¥´Ù.
¼±ÅûóÀڴ üũ°¡ µÇ¾î ÀÖÀ¸¸é ¼±ÅÃÀ» ÇÏ´Â ÄÁÆ®·ÑÀÌ´Ù.
¼±Åà »óÀÚ À̺¥Æ® Çڵ鷯 »ý¼ºView¸¦ »ó¼ÓÇÑ Å¬·¡½º°¡ ¾Æ´Ñ°÷¿¡¼ ÀÚ¹ÙÀÇ interface¸¦ ÀÌ¿ëÇÏ¿© UI À̺¥Æ® Çڵ鷯¸¦ ó¸® ÇÑ´Ù.
public class MainActivity extends ActionBarActivity
implements CompoundButton.OnCheckedChangeListener |
¼±Åà »óÀÚ »ý¼º
¹öÆ° »ý¼º°ú Ưº°ÇÏ°Ô ´Ù¸¥Á¡Àº ¾ø´Ù.
´Ù¸¥Á¡ÀÌ ÀÖ´Ù¸é
¼±ÅûóÀÚ¿¡¼´Â setOnCheckedChangeListener( ) ÇÔ¼ö·Î ¸®½º³Ê°¡ µÇ´Â ¿ÀºêÁ§Æ®¸¦ ²À ¼³Á¤ÇØ¾ß À̺¥Æ®¸¦ ¹ÞÀ»¼ö
ÀÖ´Ù.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
*/
layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
int wc = LinearLayout.LayoutParams.WRAP_CONTENT;
CheckBox chk = new CheckBox( this);
chk.setText( "Check Button");
chk.setChecked(false);
chk.setTag("chkBtn1");
chk.setLayoutParams( new LinearLayout.LayoutParams( 400, wc));
chk.setOnCheckedChangeListener( this);
layout.addView(chk);
setContentView(layout);
}
|
À̺¥Æ® ó¸®
¼±Åà »óÀÚ°¡ üũ µÇ¾úÀ»¶§,
"Check Button" ¼±Åùڽº¸¦ üũ Çϸé "No" ¹®ÀÚ¿·Î ¹Ù²Û´Ù.
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked){
String tag = (String)view.getTag();
if(tag == "chkBtn1")
{
View v = (View)view.getParent();
TextView tv = (TextView)v.findViewWithTag("chkBtn1");
tv.setText("No");
}
} |
üũ »óÅ ȮÀÎ
isChecked( ) ÇÔ¼ö·Î ¼±Åà »óÀÚ°¡ üũ µÇ¾î ÀÖ´ÂÁö È®ÀÎÇÑ´Ù.
CheckBox chkbox = (CheckBox)v.findViewWithTag("chkBtn1");
boolean checked = chkbox.isChecked();
|
|