歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android中的RadioButton和CheckBox的簡單用法

Android中的RadioButton和CheckBox的簡單用法

日期:2017/3/1 11:13:11   编辑:Linux編程

RadioButton:

RadioButton要放在RadioGroup中,點擊切換產生的事件監聽是

比如性別

RadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){


@Override

public void onCheckedChanged(RadioGroup group, int checkedId){

if(femaleButton.getId() == checkedId){

Toast.makeText(Activity.this, "female", Toast.LENGTH_SHORT).show();

}else if(maleButton.getId() == checkedId){

}

});


CheckBox:

checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){


@Override

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){

if(isChecked){

.....

}else{

.......

}

});

Copyright © Linux教程網 All Rights Reserved