即興的靈感

          思維是一種藝術(shù); 藝術(shù)需要靈感。

          博客好友

          最新評(píng)論

          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)  編輯  收藏 所屬分類: Android

          主站蜘蛛池模板: 江西省| 和政县| 沐川县| 大港区| 特克斯县| 汉川市| 建平县| 南康市| 长顺县| 昭苏县| 定州市| 扎兰屯市| 郴州市| 驻马店市| 龙山县| 广州市| 张家界市| 南召县| 郑州市| 金寨县| 汪清县| 正蓝旗| 神池县| 彝良县| 莱西市| 巨鹿县| 琼结县| 海盐县| 台中市| 奉节县| 太仓市| 措勤县| 新巴尔虎右旗| 丹巴县| 临夏市| 凉城县| 乐安县| 若尔盖县| 商南县| 康乐县| 育儿|