Android CheckBox example
来源:互联网 发布:淘宝优惠券助手 编辑:程序博客网 时间:2024/06/07 03:05
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, CheckBoxDemoActivity!</string>
<string name="app_name">CheckBoxDemo</string>
<string name="chk_ios">IPhone</string>
<string name="chk_android">Android</string>
<string name="chk_windows">Windows Mobile</string>
<string name="btn_display">Display</string>
</resources>
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/chkIos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chk_ios" />
<CheckBox
android:id="@+id/chkAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chk_android"
android:checked="true" />
<CheckBox
android:id="@+id/chkWindows"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/chk_windows" />
<Button
android:id="@+id/btnDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btn_display" />
</LinearLayout>
CheckBoxActivity.java
package com.cjp.checkboxdemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
public class CheckBoxDemoActivity extends Activity {
private CheckBox chkIos, chkAndroid, chkWindows;
private Button btnDisplay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnChkIos();
addListenerOnButton();
}
public void addListenerOnChkIos() {
chkIos = (CheckBox) findViewById(R.id.chkIos);
chkIos.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//is chkIos checked?
if (((CheckBox) v).isChecked()) {
Toast.makeText(CheckBoxDemoActivity.this,
"Bro, try Android :)", Toast.LENGTH_LONG).show();
}
}
});
}
public void addListenerOnButton() {
chkIos = (CheckBox) findViewById(R.id.chkIos);
chkAndroid = (CheckBox) findViewById(R.id.chkAndroid);
chkWindows = (CheckBox) findViewById(R.id.chkWindows);
btnDisplay = (Button) findViewById(R.id.btnDisplay);
btnDisplay.setOnClickListener(new OnClickListener() {
//Run when button is clicked
@Override
public void onClick(View v) {
StringBuffer result = new StringBuffer();
result.append("IPhone check : ").append(chkIos.isChecked());
result.append("\nAndroid check : ").append(chkAndroid.isChecked());
result.append("\nWindows Mobile check :").append(chkWindows.isChecked());
Toast.makeText(CheckBoxDemoActivity.this, result.toString(),
Toast.LENGTH_LONG).show();
}
});
}
}
- Android CheckBox example
- Android Checkbox Example
- Checkbox object example
- Checkbox object example
- Struts 2 <s:checkbox> checkbox example
- Spring MVC checkbox and checkboxes example
- Android CheckBox
- Android CheckBox
- Android CheckBox
- Android-CheckBox
- Android HorizontalScrollview Example
- Android Image Rotate Example
- Android Parcelable Example
- Android Button example
- Android EditText example
- Android EditText password example
- Android RadioButton example
- Android ToggleButton example
- 弊润落幅跨越60%的无5野婆司
- auto build system and libtool usage in popular open source project
- Android的Looper类使用的5个要点
- 16进制、10进制、BCD码之间的转换
- JAVA的Clone
- Android CheckBox example
- Android中Message机制的灵活应用
- 史上最强劲的android模拟器命令详解
- Linux进程管理之执行新的程序
- struts2自定义数据类型转换器------日期转换器
- proc文件系统|linux /proc目录介绍|proc手册
- C++ string 详解
- <jsp:param>动作标记的用法详解
- MySQL安装1045错解决办法(绝对经典)