반응형
안드로이드 체크박스(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>
실행결과
반응형
'Language > Android' 카테고리의 다른 글
| Unable to execute dex: Multiple dex files define Lrsearch/connector/CalcBase; (0) | 2013.06.04 |
|---|---|
| 안드로이드 SVN(Subversion) (12) | 2013.05.31 |
| 안드로이드(Android) TextWatcher(comma) (0) | 2013.03.08 |
| 안드로이드(Android),자바(JAVA) 소수점 자르기 (6) | 2013.03.07 |
| 안드로이드(Android) 메뉴 옵션 예제 (0) | 2013.02.26 |
| 안드로이드(Android) SDK 설치 방법 (8) | 2013.02.14 |
| 안드로이드 시크바(Android SeekBar) (2) | 2013.02.07 |
| 안드로이드 스피너(Android Spinner),콤보박스 (4) | 2013.02.06 |
| 안드로이드 웹뷰(Android WebView) 예제 (11) | 2013.02.06 |
| 안드로이드 프로그레스바(Android ProgressBar) (0) | 2013.01.30 |