Language/Android
안드로이드 체크박스(Android checkbox) 예제
준콩이
2013. 2. 26. 09:35
반응형
안드로이드 체크박스(Android checkbox) 예제 소스입니다.
MainActivity.java
package com.example.h5bak_checkbox; 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(); } } } }); } }
activity_main.xml
<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="체크박스"></CheckBox> </LinearLayout>
실행결과
반응형