本文實例講述了Android編程單選項框RadioGroup用法。分享給大家供大家參考,具體如下:
今天介紹的是RadioGroup 的組事件.RadioGroup 可將各自不同的RadioButton ,設限于同一個Radio 按鈕組,同一個RadioGroup 組里的按鈕,只能做出單一選擇(單選題).
首先,我們先設計一個TextView Widget ,以及一個RadioGroup ,并將該RadioGroup 內放置兩個RadioButton ,默認為都不選擇,在程序運行階段,利用onCheckedChanged 作為啟動事件裝置,讓User選擇其中一個按鈕,顯示被選擇的內容,最的將RadioButton 的選項文字顯示于TextView 當中.
下面我們看一下效果圖:

下面是涉及的相關代碼:
string.xml:
<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World, RadioGroupDemo</string> <string name="app_name">RadioGroupDemo</string> <string name="tr_radio_op1">帥哥</string> <string name="tr_radio_op2">美女</string> <string name="str_radio_question1">請問你是?</string></resources>
主布局main.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <!--第一 主站蜘蛛池模板: 晴隆县| 百色市| 微山县| 阿拉善右旗| 喜德县| 德州市| 昔阳县| 佛教| 鹤岗市| 佛学| 永定县| 盐边县| 嘉黎县| 墨竹工卡县| 当雄县| 涪陵区| 嵩明县| 衡阳县| 崇义县| 德州市| 抚州市| 株洲县| 车险| 勃利县| 汉阴县| 扶余县| 洛隆县| 贞丰县| 浪卡子县| 乌海市| 漳平市| 绥德县| 德庆县| 定远县| 霍州市| 简阳市| 鄱阳县| 图片| 共和县| 绥棱县| 芮城县|