單選事件
單選事件的監聽接口:RadioGroup.OnCheckedChangeListener
RadioButton與RadioGroup組合使用才能實現單選功能
* 案例:選擇字符集
通過對RadioButton控件的選擇監聽,實現對字符集的選擇
* 界面設計
* 代碼實現
private void singleCheck() {
final TextView charSet=(TextView)findViewById(R.id.charSet);
RadioGroup radioGroup=(RadioGroup)findViewById(R.id.radioGroup1);
//對單選組添加選擇監聽事件
radioGroup.setOnCheckedChangeListener(new RadioGroup.
OnCheckedChangeListener() {
/** 選擇狀態改變監聽
* RadioGroup:單選組
* checkedId:被改變的控件的資源id
*/
public void onCheckedChanged(RadioGroup group, int checkedId) {
//通過通過findViewById找到所選擇的RadioButton
RadioButton radioButton=(RadioButton)findViewById(checkedId);
charSet.setText(radioButton.getText().toString());
}
});
}