即興的靈感

          思維是一種藝術(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)  編輯  收藏 所屬分類(lèi): Android

          主站蜘蛛池模板: 固原市| 城步| 南丰县| 成武县| 江油市| 正蓝旗| 恩施市| 曲松县| 河曲县| 高州市| 高雄县| 卢氏县| 孟连| 社会| 南皮县| 北票市| 邢台市| 福鼎市| 榆中县| 尚志市| 建瓯市| 黄浦区| 高淳县| 镇安县| 水富县| 新郑市| 乳山市| 修水县| 布尔津县| 岑溪市| 清新县| 东乌珠穆沁旗| 靖宇县| 弥渡县| 光山县| 华蓥市| 玛曲县| 江城| 山阴县| 万安县| 大英县|