여러 개의 라디오 버튼 (RadioButton) 그룹을 추가하는 방법
여러 개의 라디오 버튼 (RadioButton) 그룹을 배치하고 싶지만, 어떻게해야하나요?
Android 애플 리케이션은 PC 양식 응용 프로그램이나 Web 사이트에 비해 화면이 작습니다.
그래서 A, B 중 하나를 선택 라디오 버튼의 조합과, C, D 중 하나를 선택 라디오 버튼의 조합을 배치한다,라고하는 것은별로 없을지도 모릅니다.
Spinner를 사용하면 좋잖아 · · ·.
라고 생각합니다.
그렇지만, 아무 래도 RadioButton 구현하고 싶다는 경우도 있을지도 모릅니다.
그래서, 여러 RadioButton 조합을 배치하는 방법을 소개합니다.
그 전에 조금 여담입니다.
내가 먼저, Android에서는 풀다운 메뉴는 없다? 라고 생각했습니다.
이유는 "ComboBox"라든가 "PullDown"라는 느낌의 이름 View가 없었기 때문입니다.
설마, Spinner라는 이름은 · · ·.
그 Spinner의 존재를 아직 몰랐다 Android 초보자 나는 RadioButton를 사용하기로 생각했습니다.
그래서, 이번 기사는 그 때 나름대로 조사 정보입니다.
조사해도,
Android 레이아웃 XML에 RadioButton을 추가할 때 깨달았습니다.
다음은 레이아웃 XML에 View를 추가할 때 창입니다.
빨간 부분을 봐.
그야말로,라는 ViewGroup 있습니다.
그 이름도 "RadioGroup"
바로이 녀석을 사용합니다.
이 RadioGroup은 LinearLayout 등 ViewGroup뿐만 아니라 자식 요소로 View를 가질 수 있습니다.
처음으로 적었던 것처럼, A, B 중 하나를 선택 라디오 버튼의 조합과, C, D 중 하나를 선택 라디오 버튼의 조합을 배포하려면 다음과 같이하면 OK입니다.
레이아웃 XML에서는 다음과 같이됩니다.
<RadioGroup android:id="@+id/RadioGroup01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<RadioButton android:id="@+id/RadioButton01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="A"> </ RadioButton>
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="B"> </ RadioButton>
</ RadioGroup>
<RadioGroup android:id="@+id/RadioGroup02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<RadioButton android:id="@+id/RadioButton03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="C"> </ RadioButton>
<RadioButton android:id="@+id/RadioButton04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="D"> </ RadioButton>
</ RadioGroup>
Eclipse의 Android Layout Editor와 Outline 창에서 본 느낌은 다음과 같습니다. 빨간색과 같이되도록 View를 추가하면 OK입니다.
이것을 실행 시키면 다음과 같이 A, B 및 C, D 각각에 대해 하나씩 선택할 수 있도록되어 있습니다.












