기본 콘텐츠로 건너뛰기

2022 08 26 회사 워크샵

안드로이드- RadioGroup,RadioButton

잘안쓰지만 언젠가는 사용할일이 있겠지 싶은 물건. 주의할점이라고 하면 RadioGroup , RadioButton은 직계 부모 자식 간이어야 합니다.
 <RadioGroup android:layout_width="wrap_content"
  android:layout_height="wrap_content" android:id="@+id/sex"
  android:orientation="horizontal">
  <RadioButton android:layout_width="wrap_content"
   android:layout_height="wrap_content" android:id="@+id/male"
   android:text="@string/male"></RadioButton>
  <RadioButton android:layout_width="wrap_content"
   android:layout_height="wrap_content" android:id="@+id/female"
   android:text="@string/female"></RadioButton>
 </RadioGroup>
먼저 그룹값을 가져온뒤
 RadioGroup sexGroup = (RadioGroup) findViewById(R.id.sex);
그중에 선택퇸 라디오버튼을 다시한번 가져와서
 RadioButton sex = (RadioButton) findViewById(sexGroup.getCheckedRadioButtonId());
그것의 라벨내용을 사용합니다.
 sex.getText().toString();
출처  - http://marocchino.blogspot.kr/2009/10/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-%EB%9D%BC%EB%94%94%EC%98%A4%EB%B2%84%ED%8A%BC%EB%9D%BC%EB%94%94%EC%98%A4%EA%B7%B8%EB%A3%B9-android.html

댓글