Android CheckBox 的使用案例分析
public class MainActivity extends Activity {
TextView tv;
CheckBox cb1;
CheckBox cb2;@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);cb1 = (CheckBox) findViewById(R.id.checkbox1);
cb2 = (CheckBox) findViewById(R.id.checkbox2);
tv = (TextView) findViewById(R.id.textview1);cb1.setOnCheckedChangeListener(cb);
cb2.setOnCheckedChangeListener(cb);
}private CheckBox.OnCheckedChangeListener cb = new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String stv = getString(R.string.hoby);
String scb1 = getString(R.string.basketball);
String scb2 = getString(R.string.football);
if (cb1.isChecked() && cb2.isChecked()) {
tv.setText(stv + ":" + scb1 + "&&" + scb2);
} else if (cb1.isChecked() && !cb2.isChecked()) {
tv.setText(stv + ":" + scb1);
} else if (!cb1.isChecked() && cb2.isChecked()) {
tv.setText(stv + ":" + scb2);
} else {
tv.setText(stv);
}
}
};
如下是布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hoby" />
<CheckBox
android:id="@+id/checkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/basketball" />
<CheckBox
android:id="@+id/checkbox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/football" />
</LinearLayout>
您可能感兴趣的文章:
- Android checkbox的listView(多选,全选,反选)具体实现方法
- android RadioButton和CheckBox组件的使用方法
- Android在listview添加checkbox实现原理与代码
- 详解Android Checkbox的使用方法
- android开发教程之自定义控件checkbox的样式示例
- Android控件系列之CheckBox使用介绍
- Android中ListView + CheckBox实现单选、多选效果
- Android中ListView结合CheckBox实现数据批量选择(全选、反选、全不选)
- Android中自定义Checkbox组件实例
- Android中CheckBox复选框控件使用方法详解
- Android 数据存储和文件使用案例分析
- Android 数据存储和文件使用案例分析
- Android 数据存储和文件使用案例分析
- Android入门逆引手册 - 06 复选框(CheckBox)的使用
- Android之TelephonyManager类的使用案例
- android中checkbox和radiobutton的使用
- .NET如何使用内存---餐馆案例分析
- Android 使用Oprofile分析结果系统瓶颈
- 用android来实现图片的绘制以及旋转缩放案例分析
- Android中Preference的使用以及监听事件分析
- Android Audio代码分析1 - AudioTrack使用示例
- Android Audio代码分析1 - AudioTrack使用示例
- 如何分析Android的内存使用量
- Android中ListView中使用CheckedTextView和CheckBox的理解
- android中CheckBox的isChecked的使用
- 使用eclipse跟踪调试Android源码及其.classpath的作用分析
- C#中使用XML——基于DOM的案例分析
- Oracle开发之SQL语句案例—分析函数的使用
- Android 各控件的使用 - 复选框(CheckBox)
- .NET如何使用内存---餐馆案例分析[转载]