[안드로이드,Android]체크박스,CheckBox
2013. 2. 20. 16:05ㆍMobile/Android
반응형
package com.example.ggari_radio;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (buttonView.getId() == R.id.checkbox) {
if (isChecked) {
Toast.makeText(getApplicationContext(), "눌림", 1).show();
} else {
Toast.makeText(getApplicationContext(), "안눌림", 1).show();
}
}
}
});
}
}
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" >
<CheckBox
android:id="@+id/checkbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="체크박스" />
</LinearLayout>
반응형
'Mobile > Android' 카테고리의 다른 글
| [Android ,안드로이드]TextWatcher,천단위 (0) | 2013.03.07 |
|---|---|
| [Android, 안드로이드]소수점 자르기 (0) | 2013.03.06 |
| 안드로이드 sdk 설치 및 다운 (1) | 2013.02.14 |
| [안드로이드,Android]종료 다이얼로그 (0) | 2013.02.08 |
| [안드로이드,Android]seekbar ,시크바 (0) | 2013.02.07 |