RadioGroup和RadioButton(一般用于在选择中不停切换)
2016-05-17 09:02
573 查看
1.布局代码
2.类里面要实现的代码
<!-- 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; } } }
相关文章推荐
- Yii2如何批量添加数据
- 正则表达式
- Spring容器(动态代理版)
- C#调用C++DLL的小总结5---和C++的DLL的联合调试
- 从通知里启动应用的activity,返回时返回应用的主界面
- WLCardViewLayout: Card and swipe out layout of CollectView.(可以滑动删除的卡片视图布局)
- [转]浏览器退出之后php还会继续执行么?
- One function to run them all… Or just eval
- nginx tomcat集群
- justep工具使用(数据建模和组织建模一)
- 架构的本质
- Wall--POJ1113(极角排序+求凸包)
- 根据psy输出sql
- 块状链表
- (礼拜二log)java 构建层级关系的递归算法
- host切换神器 firfox hostadmin
- 解决Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.
- LeetCode 143. Reorder List
- OpenGL矩阵变换
- 摇一摇