歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Android中的RadioButton和CheckBox的簡單用法

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