android CheckBox的运用
来源:互联网 发布:怎样做网络销售 编辑:程序博客网 时间:2024/04/30 06:16
CheckBox定义一个同意协议的按钮,只要同意button才可以点击
XML代码
<CheckBox android:id="@+id/checkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/button1" android:layout_alignLeft="@+id/linearLayout1" android:text="牛仔" />
java代码
checkbox = (CheckBox) findViewById(R.id.checkbox1);checkbox.setChecked(false);button1.setEnabled(false);
checkbox.setOnClickListener(new CheckBox.OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif(checkbox.isChecked()){button1.setEnabled(true);}else{button1.setEnabled(false);}}});
定义多个CheckBox来控制同一个控件
XML代码
<CheckBox android:id="@+id/checkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/button1" android:layout_alignLeft="@+id/linearLayout1" android:text="牛仔" /> <CheckBox android:id="@+id/checkbox2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/checkbox3" android:layout_alignBottom="@+id/checkbox3" android:layout_marginLeft="27dp" android:layout_toRightOf="@+id/checkbox3" android:text="面包" /> <CheckBox android:id="@+id/checkbox3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/checkbox1" android:layout_alignBottom="@+id/checkbox1" android:layout_toRightOf="@+id/button1" android:text="黄油" />
Java代码
checkbox = (CheckBox) findViewById(R.id.checkbox1);checkbox2 = (CheckBox) findViewById(R.id.checkbox2);checkbox3 = (CheckBox) findViewById(R.id.checkbox3);//通过OnCheckedChangeListener来设置来个CheckBox对象checkbox.setOnCheckedChangeListener(checkboxlister);checkbox2.setOnCheckedChangeListener(checkboxlister);checkbox3.setOnCheckedChangeListener(checkboxlister);}private CheckBox.OnCheckedChangeListener checkboxlister = new CheckBox.OnCheckedChangeListener(){@Overridepublic void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {// TODO Auto-generated method stubString str0 = "所选:";String str1 = "牛仔";String str2 = "面包";String str3 = "黄油";//在这里进行你需要的逻辑if(checkbox.isChecked()){tview.setText(str0+str1);}if(checkbox2.isChecked()){tview.setText(str0+str2);}if(checkbox3.isChecked()){tview.setText(str0+str3);}}};
也可以使用OnTouchListener(触摸事件)来触发
checkbox.setOnTouchListener(checktouch);checkbox2.setOnTouchListener(checktouch);checkbox3.setOnTouchListener(checktouch);}private CheckBox.OnTouchListener checktouch = new CheckBox.OnTouchListener(){@Overridepublic boolean onTouch(View arg0, MotionEvent arg1) {// TODO Auto-generated method stubif(checkbox.isChecked()){tview.setText("mimi");}else{tview.setText("pipi");}return false;}};
0 0
- android CheckBox的运用
- android CheckBox的运用
- 多项选择~checkbox的简单运用
- Android 自定义的CheckBox
- android的checkBox属性
- jq CheckBox运用
- checkbox 方法运用
- jquery中checkbox运用
- android popupWindow的运用
- Android Calendar的运用
- Android Calendar的运用
- Android SQLite的运用
- Android Calendar的运用
- Android Calendar的运用
- Android Calendar的运用
- 基于MFC单文档程序的CheckBox运用
- Android程序:checkbox的使用方法
- android调整checkbox的大小
- Java Interface 是常量存放的最佳地点吗?
- 高可用集群heartbeat全攻略
- stm32 i2c通信 [操作寄存器+库函数]
- 关于zbar的libzbar.a不支持ipnone5的64bit问题
- sql递归查询问题
- android CheckBox的运用
- Linux---Nagios监控出图
- sumo生成trace,导入ns3并生成Animation过程(整理)
- NSPredicate
- 花样Android ProgressBar 史上最强大讲解
- Android解析XML总结(SAX、Pull、Dom三种方式)
- 学会释怀,学会坦然
- stm32 i2c通信 [操作寄存器+库函数]
- Win7下telnet使用