Android開(kāi)發(fā)中單選框控件RadioButton的使用
在Android中有一個(gè)復(fù)選框的控件CheckBox,本文中我們將介紹另一種相關(guān)控件,單選框控件RadioButton,與CheckBox不同的是單選框在選擇的時(shí)候只能選擇一個(gè)。
單選控件的使用一般需要與分組控件一起使用,因此需要了解這兩個(gè)控件,RadioGroup與RadioButton,RadioGroup的作用是對(duì)不同的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>
對(duì)RadioButton的事件處理,與ChenkBox不同的是,單選框控件我們只需要對(duì)其分組父控件RadioGroup進(jìn)行監(jiān)聽(tīng)即可。
RadioGroup ataaw = (RadioGroup) this.findViewById(R.id.ataawGroup);
//響應(yīng)單選框組內(nèi)的選中項(xiàng)發(fā)生變化時(shí)的事件
group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//doing actions
}
}); 文章
?
鳳凰涅槃/浴火重生/馬不停蹄/只爭(zhēng)朝夕
???? 隱姓埋名/低調(diào)華麗/簡(jiǎn)單生活/完美人生
posted on 2010-11-12 09:07 poetguo 閱讀(12571) 評(píng)論(0) 編輯 收藏 所屬分類(lèi): Android