首页 > 代码库 > 安卓_5
安卓_5
监听器
OnClickListener
OnChecjedChangeListener
//===========
1、单选按钮的基本概念
2、radiogrounp与radiobutton
3、onClickListener与OnCheckedChangeListener监听器
//=====================
什么是Radio
1.XML文件:
<RadioButton/>&<radioGroup/>
2.代码RadioButton&RadioGroup//findViewById
3.常用OnClickListener与OnChecked\ChangeListerner监听器
//==========================
<Linerlayout>
android:orientation = "vertical"
<RadioGroup
android:orientation ="horital"
<RadioButton
/>
<RadioButton
/>
/RadioGroup>//有子标签
<TextView />无
//==========================
->MainActivity
private RadioGroup radioGroup;
private RadioBUtton femaleButton;
private RadioBUtton malebutton;
RadioGroupListener listener = new RadioGroupListener();
radioGroup.setOnCheckedChangeListener(listener);
//===================
绑定监听器
class RadioGroupListener implents OnCheckedChangeListener{
public void onCheckedChanged(RadioGroup group,int checkId)
{
//==========Id 是R.java中生成的
if(checkedId == famaleButton.getId()){
System.out.println("");
}else{
}
}
}
}
//=====================
class RadioButtonListener implements android.widget.compoundButton.OnCheckedChangeListener{
public void onCheckedChanged(CompoundButton button,boolean isChecked)
{
}
}
//==========================
RadioButtonListener radionBUttonListener = new RadioButtonListener();
femaleButton.setOnCheckedChangeListener(radioButtonListener);
安卓_5