RadioGroup和RadioButton(一般用于在选择中不停切换)

1.布局代码

 <!-- radioGRoup样式 -->
    <style name="ShowMyServiceStyle">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">50dp</item>
        <item name="android:button">@null</item>
        <item name="android:gravity">center</item>
        <item name="android:textSize">14sp</item>
        <item name="android:textColor">@color/activity_my_service_name_textcolor_selector</item>
        <item name="android:background">@drawable/activity_my_service_name_selector</item>
    </style>
 <RadioGroup
            android:id="@+id/activity_show_my_service_content_radiogroup"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/my_service_left_bg_tab"
            android:orientation="vertical" >

            <RadioButton
                android:id="@+id/activity_show_my_service_breakfast"
                style="@style/ShowMyServiceStyle"
                android:text="@string/activity_show_my_service_breakfast" />

            <View style="@style/gray_underline" 
                />

            <RadioButton
                android:id="@+id/activity_show_my_service_goods"
                style="@style/ShowMyServiceStyle"
                android:text="@string/activity_show_my_service_goods" />

            <View style="@style/gray_underline" />

            <RadioButton
                android:id="@+id/activity_show_my_service_clean"
                style="@style/ShowMyServiceStyle"
                android:text="@string/activity_show_my_service_clean" />

            <View style="@style/gray_underline" />

            <RadioButton
                android:id="@+id/activity_show_my_service_maintain"
                style="@style/ShowMyServiceStyle"
                android:text="@string/activity_show_my_service_maintain" />

            <View style="@style/gray_underline" />

            <RadioButton
                android:id="@+id/activity_show_my_service_laundry"
                style="@style/ShowMyServiceStyle"
                android:text="@string/activity_show_my_service_laundry" />

            <View style="@style/gray_underline" />

            <RadioButton
                android:id="@+id/activity_show_my_service_morning"
                style="@style/ShowMyServiceStyle"
                android:text="@string/activity_show_my_service_morning" />

            <View style="@style/gray_underline" />

            <RadioButton
                android:id="@+id/activity_show_my_service_borrow"
                style="@style/ShowMyServiceStyle"
                android:text="@string/activity_show_my_service_borrow" />

            <View style="@style/gray_underline" />
        </RadioGroup>

2.类里面要实现的代码

// 给RadioGroup设置监听器
        mRadioGroupService.setOnCheckedChangeListener(new TabCheckedListener());
        // 设置默认显示的页面
        mRadioGroupService.check(R.id.activity_show_my_service_breakfast);
    /**
     * RadioGroup的监听器实现类
     * 
     * @author Administrator
     * 
     */
    private class TabCheckedListener implements OnCheckedChangeListener {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            switch (checkedId) {
            case R.id.activity_show_my_service_breakfast:
                mServiceName = "早餐";
                requestServerDatas(mServiceName);
                break;

            case R.id.activity_show_my_service_goods:
                mServiceName = "商品";
                requestServerDatas(mServiceName);
                break;

            case R.id.activity_show_my_service_clean:
                mServiceName = "打扫";
                requestServerDatas(mServiceName);
                break;

            case R.id.activity_show_my_service_borrow:
                mServiceName = "维修";
                requestServerDatas(mServiceName);
                break;

            case R.id.activity_show_my_service_laundry:
                mServiceName = "洗衣";
                requestServerDatas(mServiceName);
                break;

            case R.id.activity_show_my_service_maintain:
                mServiceName = "叫早";
                requestServerDatas(mServiceName);
                break;

            case R.id.activity_show_my_service_morning:
                mServiceName = "借物";
                requestServerDatas(mServiceName);
                break;
            default:
                break;
            }
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值