首页 > 移动平台 > 详细

android----RadioGroup

时间:2014-02-19 21:14:54      阅读:375      评论:0      收藏:0      [点我收藏+]

XML代码:

bubuko.com,布布扣
<RadioGroup 
        android:id="@+id/sexGroup"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
     //设置RadioGroup中的RadioButton是水平布局还是垂直布局 android:orientation="vertical"> <RadioButton android:id="@+id/manRadio" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:checked="true" android:text="@string/manRadio" /> <RadioButton android:id="@+id/womanRadio" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@id/manRadio" android:layout_below="@id/manRadio" android:layout_marginTop="18dp" android:text="@string/womanRadio" /> </RadioGroup>
bubuko.com,布布扣

java代码:

bubuko.com,布布扣
manRadio=(RadioButton)findViewById(R.id.manRadio);
        womanRadio=(RadioButton)findViewById(R.id.womanRadio);
        sexGroup=(RadioGroup)findViewById(R.id.sexGroup);
        sexGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
          //通过id判断用户选择的是哪个RadioButton
if(R.id.manRadio==checkedId){ Toast.makeText(MainActivity.this, "你选择了--->>男", 2).show(); }else{ Toast.makeText(MainActivity.this, "你选择了--->>女", 2).show(); } } });
bubuko.com,布布扣

android----RadioGroup

原文:http://www.cnblogs.com/zaqn/p/3555685.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!