即興的靈感

          思維是一種藝術; 藝術需要靈感。

          博客好友

          最新評論

          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

          主站蜘蛛池模板: 卢湾区| 根河市| 凉城县| 迁西县| 论坛| 姚安县| 淮北市| 县级市| 西城区| 新宁县| 思茅市| 天津市| 虹口区| 池州市| 阜宁县| 安远县| 安溪县| 长兴县| 东丽区| 汉沽区| 花莲县| 澳门| 普陀区| 莒南县| 宜兴市| 渭源县| 稻城县| 浦东新区| 股票| 南川市| 慈溪市| 曲靖市| 潞城市| 嵩明县| 辽宁省| 彝良县| 普洱| 梅河口市| 垦利县| 西峡县| 昌乐县|