public class MainActivity extends Activity {// 声明多选列表对象private CheckBox cbx1, cbx2, cbx3, cbx4;private List checkBoxs = new ArrayList();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);cbx1 = (CheckBox) findViewById(R.id.checkBox1);cbx2 = (CheckBox) findViewById(R.id.checkBox2);cbx3 = (CheckBox) findViewById(R.id.checkBox3);cbx4 = (CheckBox) findViewById(R.id.checkBox4);// 默认选项cbx1.setChecked(true);cbx3.setChecked(true);cbx1.setOnCheckedChangeListener(listener);cbx2.setOnCheckedChangeListener(listener);cbx3.setOnCheckedChangeListener(listener);cbx4.setOnCheckedChangeListener(listener);// 添加到集合中checkBoxs.add(cbx1);checkBoxs.add(cbx2);checkBoxs.add(cbx3);checkBoxs.add(cbx4);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}public void getValues(View v) {String content = "";for (CheckBox cbx : checkBoxs) {if (cbx.isChecked()) {content += cbx.getText() + "\n";}}if ("".equals(content)) {content = "您还没有选择呢";}new AlertDialog.Builder(this).setMessage(content).setTitle("选中的内容如下").setPositiveButton("关闭", null).show();}CompoundButton.OnCheckedChangeListener listener = new CompoundButton.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {CheckBox box = (CheckBox) buttonView;Toast.makeText(getApplicationContext(),"获取的值:" + isChecked + "xxxxx" + box.getText(),Toast.LENGTH_LONG).show();}};}


 

更多相关文章

  1. android三个选项的对话框
  2. java.util.ConcurrentModificationException 解决 Android
  3. Android——CheckBox【复选框】 点击事件与属性,用案例说明
  4. Android(安卓)自定义日期控件,包含月控件
  5. android中gridView中点击 item为选中状态
  6. android checkBox 的选中和取消选中
  7. shoppingcart
  8. 改变android 选项卡的背景色
  9. Android(安卓)监听各个Acitivity的生命周期

随机推荐

  1. Android(安卓)的消息队列模型
  2. Android开机向导启动流程分析
  3. Android(安卓)Camera使用小结
  4. android 跑马灯效果及相关
  5. 升级android sdk时A folder failed to be
  6. Android中字体加粗
  7. Android(安卓)源码编译 文件系统制作
  8. Android(安卓)TextView 最全的XML属性
  9. Android杂谈---Android几种预定义样式
  10. Android中蓝牙使用步骤小结