上传者: 39840515 
                                    |
                                    上传时间: 2021-11-25 20:14:16
                                    |
                                    文件大小: 81KB
                                    |
                                    文件类型: -
                                
                            
                                
                            
                                Android 开灯 关灯 checkbox Radio组件用法演示,向大家展示了如何为CheckBox和RadioButton添加监听器及开关灯业务代码,通过单击不同的按钮,切换开灯图片和关灯图片,设置程序操作状态如下:
  public void setBulbState(boolean state){
  //设置图片状态
  ImageView iv=(ImageView)findViewById(R.id.ImageView01);
  iv.setImageResource((state)?R.drawable.bulb_on:R.drawable.bulb_off);
  CheckBox cb=(CheckBox)this.findViewById(R.id.CheckBox01);  
  cb.setText((state)?R.string.off:R.string.on);		
  cb.setChecked(state);//设置复选框文字状态
  RadioButton rb=(RadioButton)findViewById(R.id.off);
  rb.setChecked(!state);
  rb=(RadioButton)findViewById(R.id.on);
  rb.setChecked(state);//设置单选按钮状态
  }