//复选框的定义方法
public void onCheckBox(View v){
CheckBox cb=(CheckBox)v;
boolean isChecked=cb.isChecked();
//判断哪一个复选框被选中
switch(v.getId()){
case R.id.city_yj:
if(isChecked){
Toast.makeText(this, cb.getText().toString(), 0).show();
}
else{
Toast.makeText(this, cb.getText().toString()+"已取消", 0).show();
}
break;
case R.id.city_bj:
if(isChecked){
Toast.makeText(this, cb.getText().toString(), 0).show();
}
else{
Toast.makeText(this, cb.getText().toString()+"已取消", 0).show();
}
break;
case R.id.city_sh:
if(isChecked){
Toast.makeText(this, cb.getText().toString(), 0).show();
}
else{
Toast.makeText(this, cb.getText().toString()+"已取消", 0).show();
}
break;
}
}
//单选框的事件方法
public void onRadioButton(View v ){
RadioButton rb=(RadioButton)v;
boolean ischecked=rb.isChecked();
//如果被选中
if(ischecked){
Toast.makeText(this, rb.getText().toString(), 0).show();
}
}
public void onCheckBox(View v){
CheckBox cb=(CheckBox)v;
boolean isChecked=cb.isChecked();
//判断哪一个复选框被选中
switch(v.getId()){
case R.id.city_yj:
if(isChecked){
Toast.makeText(this, cb.getText().toString(), 0).show();
}
else{
Toast.makeText(this, cb.getText().toString()+"已取消", 0).show();
}
break;
case R.id.city_bj:
if(isChecked){
Toast.makeText(this, cb.getText().toString(), 0).show();
}
else{
Toast.makeText(this, cb.getText().toString()+"已取消", 0).show();
}
break;
case R.id.city_sh:
if(isChecked){
Toast.makeText(this, cb.getText().toString(), 0).show();
}
else{
Toast.makeText(this, cb.getText().toString()+"已取消", 0).show();
}
break;
}
}
//单选框的事件方法
public void onRadioButton(View v ){
RadioButton rb=(RadioButton)v;
boolean ischecked=rb.isChecked();
//如果被选中
if(ischecked){
Toast.makeText(this, rb.getText().toString(), 0).show();
}
}