1.xml文件
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:contentDescription="@string/gender"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/rb_is_pass"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/is" />
<View
android:layout_width="2dp"
android:layout_height="30dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="50dp"
android:layout_marginTop="10dp"
android:background="@color/gray" />
<RadioButton
android:id="@+id/rb_not_is_pass"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/not" />
</RadioGroup>
2.java代码
public class MainActivity extends Activity{
// 单选按钮
private RadioGroup rgHaveOrNot;
// 状态:0没选 1是 2否
private String skinTestPassState = "0";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
rgHaveOrNot =
(RadioGroup) findViewById(R.id.radioGroup);
rgHaveOrNot
.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if (checkedId == R.id.rb_is_pass) {
skinTestPassState = "1";
} else if (checkedId == R.id.rb_not_is_pass) {
skinTestPassState = "2";
}
}
});
}
}