Android開發中單選框控件RadioButton的使用
在Android中有一個復選框的控件CheckBox,本文中我們將介紹另一種相關控件,單選框控件RadioButton,與CheckBox不同的是單選框在選擇的時候只能選擇一個。
單選控件的使用一般需要與分組控件一起使用,因此需要了解這兩個控件,RadioGroup與RadioButton,RadioGroup的作用是對不同的RadioButton做分組。
<RadioGroup android:id="@+id/ataawGroup"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:checkedButton="@+id/ataaw3" android:orientation="horizontal"
android:gravity="center_vertical|center_horizontal">
<RadioButton android:text="rad1" android:id="@+id/ataaw1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton>
<RadioButton android:text="rad2" android:id="@+id/ataaw2"
android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton>
<RadioButton android:text="rad3" android:id="@+id/ataaw3"
android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton>
</RadioGroup>
對RadioButton的事件處理,與ChenkBox不同的是,單選框控件我們只需要對其分組父控件RadioGroup進行監聽即可。
RadioGroup ataaw = (RadioGroup) this.findViewById(R.id.ataawGroup);
//響應單選框組內的選中項發生變化時的事件
group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//doing actions
}
}); 文章
?
鳳凰涅槃/浴火重生/馬不停蹄/只爭朝夕
???? 隱姓埋名/低調華麗/簡單生活/完美人生
posted on 2010-11-12 09:07 poetguo 閱讀(12563) 評論(0) 編輯 收藏 所屬分類: Android