Android之复选框CheckBox使用
2015-09-26 10:49
741 查看
main.xml
strings.xml
MyActivity.java
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="wrap_content<span id="transmark"></span>" android:layout_height="wrap_content" android:id="@+id/checkbox_test" android:text="@string/str_checkbox_view"/> <CheckBox android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/myCheckBox01" android:text="@string/str_checkbox01"/> <CheckBox android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/myCheckBox02" android:text="@string/str_checkbox02"/> <CheckBox android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/myCheckBox03" android:text="@string/str_checkbox03"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/checkbox_view"/> </LinearLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">myRadio</string> <string name="str_checkbox_view">CheckBox test: </string> <string name="str_checkbox01">checkbox_01</string> <string name="str_checkbox02">checkbox_02</string> <string name="str_checkbox03">checkbox_03</string> </resources>
MyActivity.java
package com.example.myRadio; import android.app.Activity; import android.os.Bundle; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.TextView; public class MyActivity extends Activity { private TextView mTextView01; private CheckBox mCheckBox01; private CheckBox mCheckBox02; private CheckBox mCheckBox03; /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //bind Element mTextView01 = (TextView)findViewById(R.id.checkbox_view); mCheckBox01 = (CheckBox)findViewById(R.id.myCheckBox01); mCheckBox02 = (CheckBox)findViewById(R.id.myCheckBox02); mCheckBox03 = (CheckBox)findViewById(R.id.myCheckBox03); mTextView01.setText("your choose are: "); //bind Listener mCheckBox01.setOnCheckedChangeListener(onCheckedChangeListener); mCheckBox02.setOnCheckedChangeListener(onCheckedChangeListener); mCheckBox03.setOnCheckedChangeListener(onCheckedChangeListener); } private CheckBox.OnCheckedChangeListener onCheckedChangeListener = new CheckBox.OnCheckedChangeListener(){ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){ String str0 = "the choose are:"; String str1 = getString(R.string.str_checkbox01); String str2 = getString(R.string.str_checkbox02); String str3 = getString(R.string.str_checkbox03); if (mCheckBox01.isChecked()){ str0 = str0 + str1 + " "; } if (mCheckBox02.isChecked()){ str0 = str0 + str2 + " "; } if (mCheckBox03.isChecked()){ str0 = str0 + str3; } mTextView01.setText(str0); } }; }
相关文章推荐
- android读入一个txt文件
- Android环境搭建
- Android IM之基于Openfire+Smack的聊天服务器的搭建与测试
- Android系统的常用权限整理
- 分享:Android -- Properties使用
- Android开发笔记---Android控件
- Android入门——Service详解及应用(一)
- Android Studio 更换debug.keystore问题
- xml解析--Pull方式
- Android中SurfaceView和view画出触摸轨迹
- Android屏幕适配
- Android_完全退出
- Android 雷达扫描效果
- Android之单选控件RadioGroup,RadioButton使用
- Android应用开发系列(一):splash引导界面开发
- Android 四种基本布局LinearLayout、RelativeLayout、FrameLayout、TableLayout
- 【Android杂谈】AsyncTask的详细使用解析
- Android解决软键盘遮挡Button
- Android 之SharedPreference使用
- android 基础3