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;
}
}
}